Dev Notes

Various Cheat Sheets and Resources by David Egan/Carawebs.

Sync a Forked Git Repo to Upstream


Git
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  git@bitbucket.org:Username/project.git (fetch)
origin  git@bitbucket.org:Username/project.git (push)

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

git remote add upstream git@bitbucket.org:vendor/original-project.git

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.

References


comments powered by Disqus