steven
steven

Reputation: 127

git fetch not working for fetch new files

I am new to Github and have checked lots of examples for fetching and pulling 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?

Upvotes: 2

Views: 8318

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522752

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.

Upvotes: 3

Related Questions