views:

165

answers:

4

I'm pretty new to Git, and like it a lot so far, but am not sure what do do here.

I've forked a github project, and am currently in the process of porting it to another language. For reference, I've created a branch of the code as it was when I made the fork. My problem now is that the original project has been updated, and I can't figure out how to pull those changes into my branch from the original master (because 'origin' points to my github project).

Follow-up question for my own education, what command will the owner of the original project have to run in order to pull a change in from my branch into his master branch?

EDIT: These answers work when I run them from my own 'master' branch, but not when I run them from my 'tracking' branch (I'm using the term loosely here because I know of a git command of the same name. Not sure what it does, though).

When I'm in my non-master branch, and run git fetch upstream, nothing happens. When I try git fetch upstream:master, it says

ssh: upstream: no address associated with name
fatal: The remote end hung up unexpectedly
A: 

You can add it to your list of remote repos and fetch/pull from it

$ git remote add first-repo-name git://github.com/first-repo-name/repo.git
$ git fetch first-repo-name
# or:
$ git pull first-repo-name

the git pull will actually merge the first-repo-name master branch to your master branch (if you are currently in that branch)

what command will the owner of the original project have to run in order to pull a change in from my branch into his master branch?

On the GitHub side, this won't be an actual command, but the result of a pull request you would have initiated.

alt text

Technically, he could add your forked repo as a remote repo on his local repo (like you did above), but if his repo is heavily forked, this becomes un-practical, hence the central "pull requests" mechanism.

VonC
Thanks for the detailed answer! Unfortunately it only works on my master branch (or maybe that's how git is supposed to work?
drhorrible
@drhorrible: the `remote add` is not dependent on any branch. The `git fetch` will fetch all branches unless you specify one. The `git push` will only merge master if you have master checked out. The pull request can be made for commits of yours registered on any branch.
VonC
+1  A: 

You can add the original repo using git remote:

$ git remote add upstream http://github.com/user/repo.git

(You can call it something other than upstream if you want, but that's the name you'll use to refer to the remote.)

To get updates, just run:

$ git fetch upstream

In order to get the changes from your repo into the upstream repo, the maintainer will have to add your repo as a remote, and then pull the changes:

$ git remote add drhorrible http://github.com/youruser/yourrrepo.git
$ git pull drhorrible your-branch:master

Or, if the upstream maintainer doesn't want to add your repo as a remote, he can reference it directly:

$ git pull http://github.com/youruser/yourrepo.git your-branch:master
mipadi
Thanks for the detailed answer! Unfortunately it only works on my master branch (or maybe that's how git is supposed to work?
drhorrible
What only works on the `master` branch?
mipadi
git fetch upstream. The remote has been added.
drhorrible
Hmm. `git fetch` should fetch all branches in a remote repo, unless you specify otherwise.
mipadi
A: 

Git is supposed to work like this, you pull the changes from your origin (be it the forked repo, or the original) into your local master. You would then use git-merge or git-rebase to get them into your local branch. Once you're happy with the result you can push back to the remote.

I think from the way you asked the question that you would be best off using git-rebase to rebase your branch on the master after you've pulled the changes from the original repo.

If you try to do all this from the commandline you're going to need to learn git-cherry. Otherwise tools like gitx or gitk are very helpful to select commits you want to merge.

iwein
+1  A: 

Github's forking help explains it pretty well:

http://help.github.com/forking/

knoopx