1

In git documentation says fetch doesnt merge with your working tree. So lets say I have these branches: master, jhonny and miguel. Let's say master is for the last production code release.

--------------------------------------------master
                         \-----------------------miguel
                          \---------------------------jhonny

Miguel and I have tracking of all branches in our local repo. Lets say Miguel commit and push his brach to the github repo. I want to have the miguel push localy. If I do fetch, what will happen? Does fetch just updates the remote repo reference? Origin in this case.

Vote down if you think this is duplicated. But I couldnt find the answer Im looking for yet.

Regards.

1 Answers1

2

Yes, git fetch only updates the local copy of the remote repo (i.e. the remote reference) - it doesn't then merge those updates into the local branch the way git pull does.

In this sense, git fetch is quite 'safe' as there are no merge issues and all of your local branches remain untouched. For a more detailed discussion, see: What is the difference between 'git pull' and 'git fetch'?

If after a git fetch you do want to merge the remote changes with the local branch, you then need to run a git merge. This is in effect what git pull does.

Community
  • 1
  • 1
Chamila Chulatunga
  • 4,856
  • 15
  • 17
  • In this case, I dont have to keep local tracking of miguel branch since I can merge local jhonny with remote miguel. Is this correct? –  Dec 04 '12 at 13:40
  • If both you and miguel are tracking the same branch on the remote (e.g. github) repo, then, no, you don't need to keep a local 'miguel' branch. All you would do is (once miguel has pushed to the remote), run a fetch, which will update your remote reference, and then at your leisure merge that with your local branch – Chamila Chulatunga Dec 04 '12 at 13:43