18

I forked a GitHub project several days ago and from its issues, I can see that the master branch has had some modifications since.

When I cd to my location directory of this project and use git pull, it says, "Already up-to-date". Why?

How do I update my fork to include the commits from the original repo?

random
  • 9,774
  • 10
  • 66
  • 83
wuchang
  • 3,003
  • 8
  • 42
  • 66
  • 1
    Blatant duplicate of super-popular question [How to update GitHub forked repository?](http://stackoverflow.com/questions/7244321/how-to-update-github-forked-repository) – Dan Dascalescu Mar 05 '14 at 05:54

1 Answers1

46

When you fork a repository, a copy of the original repository is established on your GitHub account. This permits read+write access to the "copy".

When the original repository resource has commits that would benefit your copy, follow these steps to update your fork's master branch. You could update other branches, but typical workflow is to update master against the original repository.

  1. Open a Terminal
  2. cd to your project directory
  3. git remote add upstream <url-of-original-repository>
  4. git branch and verify you are on master branch
  5. git pull --rebase upstream master

Step #5 will fetch all new commits of the "original" repository, apply them to master branch from the last merge-base, then include all of your branch's commits "on top".

Any time you need to update your fork again, simply run the command in step #5.

random
  • 9,774
  • 10
  • 66
  • 83
Jordan McCullough
  • 2,517
  • 1
  • 14
  • 7
  • Another question please ,after I modified some code ,and according to github tutorial , I use "git push origin master" to push the modification to my forked project.after that ,I pull request , github says: "There isn't anything to compare. nferraz:master is up to date with all commits from VicoWu:master. Try switching the base for your comparison." It seems that my push takes no effect.Why this happened? – wuchang Sep 17 '13 at 02:59
  • Push pushes your local commits to your remote repository (ie. github). If those are the only commits to the remote repository since your last pull, there's nothing to pull because you already have the commits. :) – Iain Sep 18 '13 at 17:53