Add a branch, locally, to your forked repository to work on your changes.

Branches

Git repositories use branches to isolate work when needed. It's common practice when working on a project or with others on a project to create a branch to keep your working changes in. This way you can do your work while the main, commonly named 'master', branch stays stable. When the work on your branch is finished you merge it back into the 'master' master branch.

The diagram below shows how you can branch off of your 'master' branch, do work and then merge those changes back into 'master'. You can even branch off of a branch if you need to, the 'master' branch doesn't have to be the base.

A diagram showing a horizontal line, representing the master branch, with another line branching off the top and later re-joining the original. Another line branches off the master branch line from below and yet another branch branches off of that. Both of these meet back up with the original master line, too.

For a great visualization on how branches work in a project, see this GitHub Guide: guides.github.com/overviews/flow

GitHub Pages

GitHub will automatically serve and host static website files in branches named 'gh-pages'. This free service is called GitHub Pages. Since the project you forked creates a website, its main branch is named 'gh-pages' instead of 'master'. All repositories that have a 'gh-pages' branch with website files can be found, live online, using this pattern for the URL:

http://githubusername.github.io/repositoryname

Create a branch

When you create a branch, Git copies everything from the current branch you're on and places it in the branch you've requested be made.

While still inside of your local 'patchwork' repository, type git status to see what branch you're currently on. Git should reply that you're on the 'gh-pages' branch.

Now create a new branch and name it "add-<username>", where 'username' is your username. For instance, "add-jlord". Branches are case-sensitive so name your branch exactly the way your GitHub name appears.

git branch <BRANCHNAME>

Now you have a branch with a new name that is identical to 'gh-pages'.

To go into that branch and work on it you checkout a branch. Go on your new branch:

git checkout <BRANCHNAME>

Step: Create a new file

Back in your text editor:

  • Create a new file named "add-<USERNAME>.txt", where 'username' is your username. For instance, "add-jlord.txt".
  • Then, just write your GitHub username in it, that's it and that's all. For instance, I'd type 'jlord'.
  • Save this file in the 'contributors' folder in Patchwork: Patchwork/contributors/add-yourusername.txt
  • Next, check in your changes (see below).

Check-in

Go through the steps for checking in a project:

git status

git add <contributors/FILENAME>

git commit -m "commit message"

Now push your update to your fork, 'origin', on GitHub:

git push origin <BRANCHNAME>

Please select your repository directory.

Permission denied...error: 403

You are pushing changes to a repository you don't have write access to. In this case, you're likely pushing to the original 'jlord/patchwork'. Make sure that you're pushing to 'origin' and that it points to your fork's address on GitHub. To check and see what your remotes are and where they point run git remote -v. You should have 'upstream' pointing to 'jlord/patchwork' and 'origin' pointing to 'yourusername/patchwork'.

To fix a remote that is pointing to the wrong place you can re-set its url: git remote set-url origin .

Authentication failed...error: 401

Your identity could not be verified. You may have 2FA (Two Factor Authentication) turned on in which case you must use a personal access token as your password. You can generate one by following these instructions. You'll need to keep this and use it in place of your password when prompted. You can also save this access token on your computer so that you don't have to re-enter it.

File NOT in contributors folder

The file you create should be placed inside the existing 'contributors' folder in the Patchwork repository. If you put it somewhere else, simply use Finder or Windows Explorer to move your file into the folder. You can check git status again and you'll find it sees your changes. Stage and then commit "all" (-A) of these changes (additions and deletions) with the commands below.

git add -A

git commit -m "move file into contributors folder"

Branch name expected: _____

The branch name should match your user name exactly. To change your branch name:

git branch -m <NEWBRANCHNAME>

When you've made your updates, verify again!

  • You can create and switch to a branch in one line
  • git checkout -b <BRANCHNAME>
  • Create a new branch
  • git branch <BRANCHNAME>
  • Move onto a branch
  • git checkout <BRANCHNAME>
  • List the branches
  • git branch
  • Rename a branch you're currently on
  • git branch -m <NEWBRANCHNAME>
  • Verify what branch you're working on
  • git status