git fetch doesn't update my local repository

When you fetch you get the remote branches, but you still need to merge the changes from the remote branch into your local branch to see those changes.

After fetching, try this:

git log origin/yourbranchname | head
git log yourbranchname | head

Do you see the difference?

Now do:

git checkout origin/yourbranchname -b newbranchname
git log newbranchname

You should see remote changes in the newbranchname.

You can also merge those changes into your branch with

git checkout yourbranchname
git merge origin/yourbranchname

I faced this issue before, the main reason is that you didn't config the remote.origin.fetch in your git local config.

use below command to fix your issue:

git config --local --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*

after that, run 'git fetch origin', i think you will get the expected output.


git fetch just brings the changes to the local copy of the remote branch. If you want to update your repo or local branch you have to follow the fetch with a merge, or else just use git pull for one-shot.

Great SO answer: https://stackoverflow.com/a/292359/102371

Tags:

Git

Git Fetch