I collaborate on a couple of projects with a friend of mine using Github. Generally he creates most of the content but asks me to check or test it before using it in teaching. We’ve found using forks to be the simplest way to collaborate in this way, because:
- It allows me to create my own copy of his work, so any changes I make to my version don’t affect his original (unless we want them to).
- I can always download the most up to date version of his repository so I know I’m always checking the right material.
- I can track my own changes in my local copy of the repository and submit them when I’m ready.
To Fork a Repository
- Make sure you’re logged in to your github account.
- Browse github to the original repository, in my case I look for my friend’s original code.
- Press ‘Fork’ along the top left of the browser screen.
- Once the github servers finished the procedure you’re presented with your own forked repository (check the breadcrumb trail and it should say ‘forked from…’)
- Copy the SSH or HTTPS link to your (forked!) repository to your clipboard.
- Open terminal and navigate to the folder you want your local copy of your repository to be stored. For example, I place all my local git repositories in gits/local-repo-name
- Type git clone and paste your SSH or HTTPS link, so for example: git clone email@example.com:philmikejones/my-forked-repo.git
Next you need to tell github where the upstream repository is. The upstream is the original repository owned by your friend or colleague that you forked above. By specifying the upstream location this means you can suggest changes you make to your fork back to the original author, so it’s kinda essential.
- Navigate to the original repository (click ‘forked from…’ at the top of your forked repository).
- Copy the SSH or HTTPS link as before.
- Back in terminal, make sure you’re in the correct folder (i.e. for me it’s gits/my-local-forked-repo). To do this you’ll probably need to navigate to the folder your fork just created.
- Type git remote add upstream and paste the link, so for example: git remote add upstream firstname.lastname@example.org:original-author/upstream-repository.git
- If you get an error saying ‘fatal: Not a git repository’ then you’re in the wrong folder in your terminal.
- To check this worked type git remote -v. You should have both an origin (your fork) and an upstream (the original).
- Finally, type git merge upstream/master so git knows which branches relate to each other across the fork.