Dev Notes

Software Development Resources by David Egan.

Sync a Forked Git Repo to Upstream

David Egan

When you have forked a repo, it can be useful to pull in changes that have been made to the original.

Git makes this pretty straightforward.

Configure Git Remote

To list the current remotes in your project, cd into the repo directory and run:

git remote -v

# Outputs:
origin (fetch)
origin (push)

Configure a git remote that points to the upstream repo (the original that you forked from):

git remote add upstream

Sync to the Upstream Repo

  • Fetch data from the upstream repo - commits to master will be stored in a local upstream/master branch
  • Checkout the fork’s master branch (if you’re not already on master)
  • Merge changes from upstream/master:
git fetch upstream

git checkout master

git merge upstream/master

Automatic Synchronization

Bitbucket allows automatic fork synchronization - this is enabled in the Bitbucket GUI when you first fork the repo. I’ve not used this feature.


comments powered by Disqus