Updating a Fork of a Repo in GitHub

This is a reminder post! I keep forgetting the steps I take to update a forked repo in GitHub with the latest version from the source repo (using the command line), so here’s what I do for anyone else that needs to do the same.

The assumption are that:

  • You have a forked repo which is behind another repo’s updates, in GitHub.
  • Locally, you have no copy of your forked repo (but that isn’t essential - just adapt the steps).

I’ll use a repo I recently worked with for the excellent blog by Brent Roose.

Cloning your GitHub repo locally

1
$ git clone https://github.com/s-moon/stitcher.io.git

Change the repo above to be your repo.

1
$ git remote add remote https://github.com/brendt/stitcher.io.git

Here, the source repo is Brent’s - it’s the one I originally forked. I’m also creating a remote named “remote” - the second usage of remote.

Taking a copy of the changes

1
$ git pull remote

These are Brent’s changes that he has added since to his original repo.

See changes

If you like, you can see the changes that were retrieved with this command:

1
2
3
4
$ git branch -va

remotes/origin/...
remotes/remote/...

Make sure master is checked out

1
$ git checkout master

Merge the changes in

1
$ git merge remote/master

Here, we’re merging in the new changes that we don’t have.

Finally, push them to your forked repo in GitHub

1
$ git push

Lastly, push all these changes to your forked repo.


Hi! Did you find this useful or interesting? I have an email list coming soon, but in the meantime, if you ready anything you fancy chatting about, I would love to hear from you. You can contact me here or at stephen ‘at’ logicalmoon.com