Skip to content

Instantly share code, notes, and snippets.

@hennasingh
Forked from OyaCanli/syncYourFork.md
Created December 6, 2018 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hennasingh/e5b165b824cae467a0a0cc0e6c9762a5 to your computer and use it in GitHub Desktop.
Save hennasingh/e5b165b824cae467a0a0cc0e6c9762a5 to your computer and use it in GitHub Desktop.
How to sync your fork when collaborating on github
When you want to collaborate on a project for the first time, you fork the project and then clone your fork to your PC.
When you clone a repo from github, it automatically adds that address as a remote address for your local project
and when you later call git push, it pushes your changes to that remote (which is your fork on github, and which is by convention
named as origin). If you call *git remote -v* at this stage on git bash/command you'll see the address of your own fork as remote origin(both for pulling and pushing)
However, when there is a change in the original repo that you forked, the changes won't be reflected in your local
copy, neither in your fork on github. It doesn't help to call git pull or press update on AS, because the default destination for
updating is your fork on github, which is not updated either.
So, you need to fetch directly from the original repo that you forked. For this, you need to add it as a second remote address.
By convention, we name this remote as upstream. You can add remote upstream like this:
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
After adding this remote, if you call "git remote -v" again, you should be able to see both your own fork and the original repo as
alternative remote addresses.
Once you done that, each time there is a change in the repo and you want to update your local version, you'll need to call:
git fetch upstream
You'll see things like: Counting objects, compressing objects etc.. Like shown here: https://help.github.com/articles/syncing-a-fork/
Make sure you're on the correct branch. And then merge the correct branch of the upstream into your local copy:
git merge upstream/branch_you_want_fetch
This will update your local version.
You might notice that your fork on github is still not updated.
It will get updated when you push your changes. (We push our changes to our fork and then make a pull request. Unless you are assigned
as a collaborator to the original project and given rights to directly push to the original repo,
you can't push to the original repo directly)
Of course, I assume that you're in a clean state: that you do not have any commits that doesn't exists
in the upstream or unstashed changes. In order to avoid such conlifts, always make sure that your repo is up-to-date before
making further changes. It would be also better to communicate with the other members who work on the same code.
It is possible to work on the same time and make different changes on the same repo, but the owner of the repo
will have to deal with merge conflicts in that case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment