Reputation: 2696
I was going through git scm book and reading the Pulling section on this page. It says:
While the git fetch command will fetch down all the changes on the server that you don’t have yet, it will not modify your working directory at all. It will simply get the data for you and let you merge it yourself.
I have used 'git fetch upstream' and it does merge all the changes existing in the remote branch to my local branch, which according to me updates the working directory as well. But then it contradicts the above statement.
I am confused and not able to get my head around it. Can someone please explain?
I have already gone through the links which are marked as duplicate. I may as well be dumb but I didn't get any clarity of the above statement from those answers. Please help.
Update
Here's the command that I ran and its output:
bash-3.2$ git fetch upstream
remote: Counting objects: 108, done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 108 (delta 77), reused 77 (delta 77), pack-reused 23
Receiving objects: 100% (108/108), 25.92 KiB | 0 bytes/s, done.
Resolving deltas: 100% (79/79), completed with 31 local objects.
From <git-repo-url>
a82339d..9844eeb master -> upstream/master
802bae5..6c84bfb <some-branch> -> upstream/<some-branch>
Upvotes: 2
Views: 236
Reputation: 23256
I have used 'git fetch upstream' and it does merge all the changes existing in the remote branch to my local branch, which according to me updates the working directory as well. But then it contradicts the above statement.
git fetch
doesn't update your local branches nor your working directory.
You might think it updates a local branch, given a line like this,
a82339d..9844eeb master -> upstream/master
but according to the Output section in the git-fetch
manual, this means that
master
is the name of the "ref" (a branch is one kind of ref) in the remote repository being fetched from, andupstream/master
is the name of the ref in the local repository being updated.Note that the branch master
in the local repository is not updated.
Upvotes: 2
Reputation: 1045
Not sure why this is generating confusion....anyway: the comment you mentioned is exactly what git fetch is doing. Please have a look at old What is the difference between 'git pull' and 'git fetch'?
For example:
git fetch origin
--> will fetch the changes but not merge into yours
git merge origin/master
--> has to be used to merge afterwards.
Other way to do this in a fashion and fast way is to use pull:
git pull origin(whatever)
--> will do both in one shot.
Hope this clarify a bit your doubts :-) Have a nice day!
Upvotes: 1
Reputation: 205
The difference is that a git pull does a git fetch followed by a git merge to update your local branch.
Upvotes: 1