repo

Sync a github forked repo

Snippet

Forking a github repo inherently takes it out of the originating repo flow. Sync it back this way.

# check your remotes
git remote -v
 
# origin  git@github.com:YOUR_USERNAME/YOUR_FORK.git (fetch)
# origin  git@github.com:YOUR_USERNAME/YOUR_FORK.git (push)
 
# add the remote
 
git remote add upstream git@github.com:ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
 
# note, the original docs assume you don't have a github account set up properly.  If not, do this one:
# git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
 
# and confirm
 
git remote -v
 
# might look like this:
# origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
# origin    https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
# upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
# upstream  https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)
 
# get the changes from the originating repo
 
git fetch upstream
 
# check out the master branch to sync to
 
git checkout master
 
# and sync away
 
git merge upstream/master
 
# then back to your branch and continue
 
git co this-is-my-branch
git rebase master
git push --force origin this-is-my-branch
 
# etc.