views:

284

answers:

3

I have set up some remote tracking branches in git, but I never seem to be able to merge them into the local branch once I have updated them with 'git fetch'.

For example, suppose I have remote branch called 'an-other-branch'. I set that up locally as a tracking branch using

git branch --track an-other-branch origin/an-other-branch

So far, so good. But if that branch gets updated (usually by me moving machine and commiting from that machine), and I want to update it on the original machine, I'm running into trouble with fetch/merge:

git fetch origin an-other-branch
git merge origin/an-other-branch

Whenever I do this, I get an 'Already up-to-date' message and nothing merges.

However, a

git pull origin an-other-branch

always updates it like you would expect.

Also, running git diff

git diff origin/an-other-branch

shows that there are differences, so I think I have my syntax wrong.

What am I doing wrong?

EDIT [2010-04-09]: I have checked a couple of times, and I'm definitely not on a different branch. Should my 'git fetch' followed by a 'git merge' (as shown above) do the exact same thing as a git pull? I will get some workflow showing the results of a git status etc.

+3  A: 

Are you sure you are on the local an-other-branch when you merge?

git fetch origin an-other-branch
git checkout an-other-branch
git merge origin/an-other-branch

The other explanation:

all the changes from the branch you’re trying to merge have already been merged to the branch you’re currently on.
More specifically it means that the branch you’re trying to merge is a parent of your current branch

if you're ahead of the remote repo by one commit, it's the remote repo that's out of date, not you.

But in your case, if git pull works, that just means you are not on the right branch.

VonC
i had the same issue and this helped me a lot, thanks
Senthil A Kumar
+1  A: 

Git pull is actually a combo tool: it runs git fetch (getting the changes) and git merge (merging them with your current copy)

Are you sure you are on the correct branch?

RDL
+4  A: 

You don't fetch a branch, you fetch an entire remote:

git fetch origin
git merge origin/an-other-branch
Gareth
Chris Johnsen
so if origin has 1000 branches, you'd a remote branch for all of them?
Gauthier
Sure. If I've added a remote repository with 1000 branches to mine, and I ask what branches the remote has, it damn well **better** give me all 1000
Gareth
i had the same issue and this helped me a lot, thanks
Senthil A Kumar