Github: Updating a forked repo

This one is entirely for me.  I know this is pretty basic stuff, but I don’t do this often enough to remember the steps and finally got sick of looking it up each time.

Here’s the scenario this covers: In my Github account, I have a forked copy (I’ll call this origin) of a repo owned by someone else (I’ll call this upstream).  I also have a local copy on my development machine (I’ll call this local).  The owner of upstream is continuing to make changes, and I am making changes to local and pushing them to origin.  Periodically, I need to pull copies made to upstream into my development efforts (local and origin) to make sure I’m not going to have problems merging my changes into upstream when I’m ready.

Here are the steps:

  1. [Only the first time you go through this process]: From a git bash prompt in your local git repo folder, add a git remote pointing to upstreamgit remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
  2. Fetch upstream to local: git fetch upstream
  3. Make sure you have local/master checked out: git checkout master
  4. Merge upstream/master with local/master: git merge upstream/master.  If you have local changes to files that are part of the merge, you’ll need to commit or stash them first.
  5. You now have an updated copy of upstream merged with local.  All you need to do is push it to origin: git push origin master

All done.

2 thoughts on “Github: Updating a forked repo

  1. Lori

    This article is really cool. I have bookmarked it. Do you allow guest
    post on your site ? I can provide hi quality
    articles for you. Let me know.

  2. Jim91

    I see your blog is similar to my page. Do you allow
    guest posts? I can write high quality & unique articles for you.
    Let me know if you are interested.

Comments are closed.