Git/Sync a Fork
From charlesreid1
If you have forked a remote repository using git, and it has fallen behind several commits, you may need to sync your fork.
Here's how to do that.
updating branch with same name as remote
This supposes you are trying to update your master branch with the fork's master branch.
We'll use the hypothetical Github repos https://github.com/ours/repo for the fork and https://github.com/theirs/repo for the original (forked) repo.
# Start by forking the repo on Github... # Check out the fork git clone https://github.com/ours/repo # Add the original (forked) repo as the "upstream" cd repo/ git remote add upstream https://github.com/theirs/repo # Do some work... # Oh no, we missed a bunch of changes to the upstream repo! # Fetch upstream changes git fetch upstream # Checkout the master branch of the fork # (this assumes the master branch of the original, forked repo is what we want to update from) git checkout master # Merge the changes from upstream/master into your local master branch. git merge upstream/master
updating branch with different name as remote
Suppose we have forked an upstream repository. Further suppose we have a current branch in our fork called oxen
and we want to merge changes to the upstream's master
branch. We can do this:
$ cd my-fork/ $ git checkout oxen $ git pull upstream master
This will create a commit that merges changes from upstream's master
into the local branch oxen
.