I am new to Github and have checked lots of examples for fetch
ing and pull
ing files from the Git server. However, my fetch
command does not work as I expected; my pull
command works as I expected and downloads new files onto my system. Is the fetch
command not able to download files locally to my branch?
1 Answers
You need to understand the difference between fetching and pulling. When you do a fetch:
git fetch
you update all the local tracking branches in your Git folder. The tracking branches are your local copy of what is actually on the repository, and it is these branches which Git uses for most operations. This means that every tracking branch will now be in sync with the latest changes from GitHub. However, this does not mean that the local branch you have is now up to date. To bring your local branch up to date you have to additionally either merge or rebase that branch on the remote tracking branch.
Assuming you are on the master
branch, you can remember what git pull
does as follows:
git pull = git fetch + git merge origin/master
In other words, there is merge here to actually get the changes from the remote repository into your local branch. You could also rebase your local branch on the version in the remote via git pull --rebase master
.
So the answer to your question is that the fetch command absolutely does bring in changes from the remote to your system, but you have to additionally merge or rebase to update your local working branch.

- 502,043
- 27
- 286
- 360
-
Strange, if i use "git merge origin/master (or my branch)" then it works after fetch but i see in other links "git merge origin master" it is not working. – steven May 25 '16 at 10:27
-
`git merge origin master` means merge your local branch into itself. This doesn't make any sense logically. `origin/master` is the local version of the remote branch and this is what you want to merge into your local branch. – Tim Biegeleisen May 25 '16 at 10:29
-
Should "When you do a fetch [...] you update all the local tracking branches" instead read, "[...] you update all the remote branches"? See [this answer to a different post](https://stackoverflow.com/a/16408515/3276252) for why I ask. – Babak May 09 '19 at 19:05