git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
By default, the remote origin
would be set to [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
Now add a new remote to point to the original repository from which you forked.
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
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.
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