git fetch doesn't update my local repository

77,090

Solution 1

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

Solution 2

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.

Solution 3

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

Share:
77,090
Rodrigo
Author by

Rodrigo

I am actualy working for Banco do Brasil, building the app programs in Objective-C.

Updated on August 05, 2022

Comments

  • Rodrigo
    Rodrigo over 1 year

    What I want:

    Update all news commits from server with my local repository in all branch but do not merge any branch (just join the history lines).

    I am trying this command

    git fetch --force --progress --verbose  name@host:/path/to/repository.git 
    

    I thought it will work fine, because it show:

    From host:/path/to/repository
      * branch            HEAD       -> FETCH_HEAD
    

    But, what means this output? If I see the log, it wasn't update. If I do a clone from server, all new commits are there. So... The command not work. Then I try with a branch that exist in server but not in my local repository

    git fetch --force --progress --verbose  name@host:/path/to/repository.git my_branch
    

    The result is:

    From host:/path/to/repository
      * branch            my_branch       -> FETCH_HEAD
    

    And any success... Even if I not know all branches and my branch was update, I want to fetch this changes and can see in my log.

    Any idea to do it work?

    • CharlesB
      CharlesB about 12 years
      Can you explain what means join the history lines for you?
    • Rodrigo
      Rodrigo about 12 years
      I can say: do the merge in history... But not from 2 branches. In other words, I just want update all the history, and only this.
    • CharlesB
      CharlesB about 12 years
      What you want is called fast-forward merge. It only applies when histories have not diverged. If it is the case git pull master (equivalent to git fetch + git merge origin/master) will automatically do this if histories have not diverged.
    • Rodrigo
      Rodrigo about 12 years
      @CharlesB you are correct. And what I want is git pull --no-commit. Now I do not understand the why of git fetch. It just download from server, so I can do other task in offline mode?
  • Rodrigo
    Rodrigo about 12 years
    But, this merge mean another commit, so it can fail because a conflict. I will do a fetch, do some checks and than do the merge. When you say: git fetch just brings the changes to the local copy of the remote branchthis is exactly what I want to do, but it not work
  • Rodrigo
    Rodrigo about 12 years
    Ok, git fetch do not update the history, but the "data", so I can set off-line and do this merges. This is what fetch do?
  • George Skoptsov
    George Skoptsov about 12 years
    Fetch downloads remote branches, but it doesn't update local branches. When you merge remote branches into your local ones, you update local branches. You can see "history" on both local and remote branches. Try gitk yourbranchname and gitk origin/yourbranchname.
  • Rodrigo
    Rodrigo about 12 years
    I do it. But I just see the local changes from that branch. I can have make something wrong, but now I understand what stash do. What I want to do is just git pull --no-commit this was what I thought fetch do :)
  • hejdav
    hejdav almost 8 years
    The true reason for the OP issue is, as YOU say - Current local branch has no remote one!
  • Michael Armes
    Michael Armes about 7 years
    This worked for me -- helped for a very frustrating morning!
  • Abhishek Singh
    Abhishek Singh over 3 years
    it solved my issue, but I am wondering why do I need to set this in a fresh git installation? I did "git clone repo_url --depth 1" and "git fetch --unshallow"