107

I forked a project on github, made some changes, so far so good.

In the meantime, the repository I forked from changed and I would like to get those changes into my repository. How do I do that ?

5 Answers 5

91

Generally git pull is enough, but I'm not sure what layout you have chosen (or has github chosen for you).

4
  • 5
    git pull is not going to work unless you've configured the remote to fetch from and the branch to merge to.
    – Abizern
    Nov 30, 2010 at 11:53
  • I'm assuming that was done during the "making a fork" phase. Unless this information was thrown away, it should still be there. Nov 30, 2010 at 11:54
  • using git pull with https didn't work, but with http it did...now I'm up to date, Thanks! Nov 30, 2010 at 11:59
  • @GeorgeProfenza That's not safe. Consider using ssh
    – JVE999
    Jul 25, 2014 at 1:24
71

Assuming their updates are on master, and you are on the branch you want to merge the changes into.

git remote add origin https://github.com/<github-username>/<repo-name>.git
git pull origin master

Also note that you will then want to push the merge back to your copy of the repository:

git push origin master
8
  • adding worked, pulling didn't :(, I got an error related to https: error: Protocol https not supported or disabled in libcurl while accessing github.com/mrdoob/three.js.git/info/refs fatal: HTTP request failed Hints ? Nov 30, 2010 at 11:32
  • What platform? Looks like one of git's dependencies is not complete. Nov 30, 2010 at 11:39
  • As a work around you can also use the git protocol rather than https, e.g. git remote set-url git://github.com/mrdoob/three.js.git - then try the git pull. Nov 30, 2010 at 11:43
  • running on osx. I did manage to get it using git pull github.com/mrdoob/three.js.git master Nov 30, 2010 at 11:51
  • 3
    typo in commands, I think, you start with original, then switch to origin
    – Benjol
    Nov 30, 2010 at 12:43
50

You have to add the original repo as an upstream.

It is all well described here: https://help.github.com/articles/fork-a-repo

git remote add upstream https://github.com/octocat/Spoon-Knife.git
git fetch upstream
git merge upstream/master
git push origin master
5

You need to add the original repository (the one that you forked) as a remote.

git remote add github (clone url for the orignal repository)

Then you need to bring in the changes to your local repository

git fetch github

Now you will have all the branches of the original repository in your local one. For example, the master branch will be github/master. With these branches you can do what you will. Merge them into your branches etc

3
  • 2
    I suggest the name upstream for the remote.
    – vidstige
    Mar 10, 2015 at 10:58
  • @vidstige Which isn't really descriptive enough if you have multiple remotes for a repository. For example, I frequently have a remote on Github and a remote on Dropbox.
    – Abizern
    Mar 10, 2015 at 12:35
  • well, then it of course makes sense. That's why it's great to have the ability to name them yourself. Realize your setup is probably less common than having one remote called origin that is your own fork and then you have the original, which is usually named "upstream".
    – vidstige
    Mar 10, 2015 at 12:37
1

On github UI, switch to the branch you want to update with new changes from fork. Then simply select:

fetch upstream

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.