Update a Github Fork from the Original Repo

Feather Blog has made some great progress recently and when looking to update my fork I found myself staring at my repo not sure what to do. My wonderful Github didn’t give me a one-click way to pull updates from the original repository (or any other fork for that matter). I’ll demonstrate how to do this with my fork of Feather. I’ll assume you already have a locally copy of a repo with everything committed and up-to-date.

First you need to add a remote branch to your repository that points to the original repo you forked from.

git remote add --track master mleung git://github.com/mleung/feather.git

You will want to replace ‘master’ with the branch you want to track in the remote repo. In most cases this will be master, although you could replace it with edge or any other branch. You should also replace ‘mleung’ is what you the remote will be called.

To verify the remote repository was added run

git remote

You should see the new remote repo, in this case named ‘mleung’, along with any other remote repositories you may have previously added.

Now we can fetch all the changes from mleung’s code base.

git fetch mleung

This will create a new remote branch called ‘mleung/master’. Now we are ready to merge the code from the remote repository.

git merge mleung/master

That’s it. Remember, this process isn’t limited only to the original repository. Feel free to add remote branches for other user’s forks or even from repositories outside Github.

15 Comments

  1. ves
    Posted January 25, 2009 at 2:07 am | Permalink

    Cheers for this. Git newb myself and this wasn’t that obvious :)

  2. Posted March 10, 2009 at 1:45 pm | Permalink

    Thanks for this. I just wanted to add, that instead of doing `git fetch mleung` then `git merge mleung/master`, you can do it in one step with `git pull mleung master`.

    Before your post I was doing it the old fashioned way, e.g. `git pull git://github.com/mleung/feather.git master`. You just saved me a bunch keystrokes!

  3. Posted May 2, 2009 at 9:51 am | Permalink

    Thumbs up!
    Thanks

  4. Posted May 7, 2009 at 6:59 pm | Permalink

    Thanks for the info. I just started using git this week and your post helped out a lot!

  5. Alfredo
    Posted May 10, 2009 at 11:36 am | Permalink

    Wow buddy, thats precisely what I was looking for. Thank u very much for the info!!

  6. Posted October 25, 2009 at 2:51 pm | Permalink

    I get “fatal: Not a git repository (or any of the parent directories): .git” when I try to run “git remote add –track master mleung git://github.com/mleung/feather.git”. Why?

  7. Posted November 11, 2009 at 10:02 pm | Permalink

    @Erik Nord – I think you need to change your CWD to the git repo that you want to add the remote repo to – that error usually indicates that you aren’t (locally) in a git repository.

  8. Posted July 5, 2010 at 10:08 pm | Permalink

    Thanks for the tip, worked great

  9. замена стояков отопления
    Posted February 2, 2011 at 6:34 am | Permalink

    хорошо :-) нирвана!

  10. Joe
    Posted June 12, 2011 at 10:41 am | Permalink

    So using GitHub I would typically:

    1. fork a repo
    2. clone my fork to create a local repo
    3. add ‘upstream’ remote, pointing to original repo

    Now when upstream changes happen I would:

    4. fetch from upstream into local repo
    5. merge upstream changes

    But what now? my fork on github is still not updated. My local repo contains changes fetched from upstream, but my fork on GH does not. If I try to push master to origin I just get the message ‘Everything up-to-date’.

    ???

  11. Posted September 9, 2011 at 2:46 am | Permalink

    @Joe

    You have to push to remote :)

  12. Posted January 11, 2012 at 11:26 am | Permalink

    on the github.com site you can go to your fork of the project, click the network tab, and then click fork queue. you can pull/merge changes from the parent master here. This also allows you to cherry pick changes.

  13. Steve Piercy
    Posted April 7, 2012 at 5:35 am | Permalink

    @Joe

    4. git fetch upstream
    5. git merge upstream/master
    6. git push
    7. refresh your github fork’s web page and do the happy muppet dance

  14. Tal
    Posted April 21, 2012 at 3:25 am | Permalink

    $ git fetch test
    fatal: Unable to look up https (port ) (nodename nor servname provided, or not known)

  15. gallex
    Posted April 29, 2012 at 8:30 pm | Permalink

    you wirte is just the same on the github.com, but I question is: it is only sync local repo ,but not the remote repo, I think if I make a new clone for my remote repo, it would old. dose it ?

6 Trackbacks

  1. [...] That’s it. Remember, this process isn’t limited only to the original repository. Feel free to add remote branches for other user’s forks or even from repositories outside Github. via bradlyfeeley.com [...]

  2. [...] Bradly Feeley » Update a Github Fork from the Original Repo. This was written by Daniel Drzimotta. Posted on Friday, October 1, 2010, at 9:33 am. Filed under Uncategorized. Tagged fork, git, github, merge. Bookmark the permalink. Follow comments here with the RSS feed. Post a comment or leave a trackback. [...]

  3. [...] Bradly Feeley » Update a Github Fork from the Original Repo. This was written by Daniel Drzimotta. Posted on Wednesday, November 10, 2010, at 1:33 pm. Filed under Uncategorized. Tagged forking, git, github, merging. Bookmark the permalink. Follow comments here with the RSS feed. Post a comment or leave a trackback. [...]

  4. By 短期小记 | 风骚客 on June 14, 2011 at 2:42 am

    [...] 最新的master版本(这篇文章在我不熟悉git的时候帮了我不少忙),又在他已经写好的代码上学习了google [...]

  5. By Updating a Github Fork « Steven Tseng on September 22, 2011 at 5:57 pm

    [...] Here is the link (it was a blog i found on the net): http://bradlyfeeley.com/2008/09/03/update-a-github-fork-from-the-original-repo/ [...]

  6. [...] to update these forks against their master and the Google has provided a very concise blog post here(http://bradlyfeeley.com/2008/09/03/update-a-github-fork-from-the-original-repo/). Kudo’s to Bradly Feeley. Posted by David at 3:20 pm [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*