From charlesreid1

Revision as of 23:14, 17 November 2017 by Admin (talk | contribs)

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