1. Clone your fork:
git clone email@example.com:YOUR-USERNAME/YOUR-FORKED-REPO.git
By default, the remote
origin would be set to
Now add a new remote to point to the original repository from which you forked.
2. Add remote from original repository in your forked repository:
cd into/cloned/fork-repo git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git git fetch upstream
3. Updating your fork from original repo to keep up with their changes:
git merge upstream/master or git pull upstream master
(git pull is actually git fetch + git merge) If the origin and upstream have a linear path, both the above commands will do a fast-forward merge (no merge commit). If the path is not linear, i.e. if the origin has some commits that are not in upstream, fast-forwarding cannot be done.
4. Merge commits
If accidentally because of some change in your origin, when you pull upstream, a merge commit might have been created. Once you create the first merge commit, all future sync merges will be prevented from fast-forwarding because you have a commit that is unique to your fork that does not exist on the upstream repository.
At that point, you might see the status of your branch as X commit ahead of upstream To get your fork back again in sync with upstream,
git fetch upstream git reset --hard upstream/master git push --force