gitgit-fetch

git fetch doesn't update my local repository


What I want:

Update all new commits from server with my local repository in all branches 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 worked fine, because it showed:

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

But, what does this output mean? If I see the log, it wasn't updated. If I do a clone from server, all new commits are there. So... The command does not work. Then I try with a branch that exists on the 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 no success... Even if I do not know all branches and my branch was updated, I want to fetch those changes and can see them in my log.

Any idea on how to make it work?


Solution

  • 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