How to sync with a remote Git repository?
Asked Answered
B

5

111

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 ?

Bracteole answered 30/11, 2010 at 11:16 Comment(0)
E
95

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

Eugeneeugenia answered 30/11, 2010 at 11:20 Comment(4)
git pull is not going to work unless you've configured the remote to fetch from and the branch to merge to.Smirch
I'm assuming that was done during the "making a fork" phase. Unless this information was thrown away, it should still be there.Bader
using git pull with https didn't work, but with http it did...now I'm up to date, Thanks!Bracteole
@GeorgeProfenza That's not safe. Consider using sshParricide
N
72

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
Numbat answered 30/11, 2010 at 11:19 Comment(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 ?Bracteole
What platform? Looks like one of git's dependencies is not complete.Numbat
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.Numbat
running on osx. I did manage to get it using git pull github.com/mrdoob/three.js.git masterBracteole
typo in commands, I think, you start with original, then switch to originCopter
Is there any way I can do that using only the Github for Mac client and/or the Web interface?Spoiler
Thank you! This fixed my "warning: remote HEAD refers to nonexistent ref, unable to checkout." error.Infrastructure
this one answer is the correct answer. the other one is not the correct answer, git pull aint working, at least not out-of-the-box.Adynamia
M
51

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
Meras answered 23/8, 2012 at 13:55 Comment(0)
S
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

Smirch answered 30/11, 2010 at 11:52 Comment(3)
I suggest the name upstream for the remote.Sinnard
@Sinnard 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.Smirch
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".Sinnard
W
1

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

fetch upstream
Weevil answered 30/6, 2022 at 13:0 Comment(1)
This doesn't add the branch to your fork though, and the Push will automatically try and push to the original (upstream). You need to create your own branch from the one fetched and then you can do pull requests back to the upstream repo.Guzel

© 2022 - 2024 — McMap. All rights reserved.