giant robots smashing into other giant robots

We are thoughtbot. We make web & mobile apps.

Tagged:

Comments (View)

Keeping a git fork updated

This isn’t muscle memory for me yet so I’m writing it down to refer to it later. It isn’t rocket science but it might help someone else, too.

This is for the case where you have a fork (say, croaky/dotfiles) of a main repo (say, thoughtbot/dotfiles) and you want to keep your fork updated.

Track

After you’ve forked the repo to your Github account, one time:

git clone git@github.com:YOU/REPO.git
cd REPO
git remote add upstream git@github.com:UPSTREAM/REPO.git

YOU should be replaced with your Github name, UPSTREAM means the name of the Github user who manages the upstream repo, REPO is the repo name.

Update

Each time you want to update, from your local master branch:

git fetch upstream
git rebase upstream/master

The goal of the rebase is to have a cleaner history if you have local changes or commits on the repo. It’s the difference between the the left and the right in the image below.

Commit rights upstream?

If you also have commit rights to the upstream repo, you can create a local upstream branch and do work that will go upstream there.

git checkout -b upstream upstream/master