Search code examples
gitversion-controlgit-fetch

git fetch : output that there was an update


The expected behaviour for fetch in case of an update is the following (imho):

$ git fetch -p
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From AAA
   a061e40..2058467  develop    -> origin/develop

This works for me in project A. Fetching from the same git host, same local system, different project (say, project B), git fetch gives me no output. I think it has changed at some point in time but I cannot make out what the cause was.

Project B, git fetch output:

$ git checkout develop
Switched to branch 'develop'
Your branch is up-to-date with 'origin/develop'.
$ git fetch -pv
From BBB
 = [up to date]      develop                       -> origin/develop
$ git status
On branch develop
Your branch is behind 'origin/develop' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Project A config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    precomposeunicode = true
[remote "origin"]
    url = AAA
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

$ git branch -vv
* develop    a061e40 [origin/develop: behind 1]

Project B config:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    precomposeunicode = true
[remote "origin"]
    url = BBB
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[branch "develop"]
    remote = origin
    merge = refs/heads/develop

$ git branch -vv
* develop                       7d1afd6 [origin/develop: behind 2]

How can I change the behavior of git fetch in project B back to how it behaves in project A?


Solution

  • You can check your current develop branch commit id with .git\refs\remotes\origin\develop.

    If the two commits are the same, that means your local develop branch is really up to date.

    If the two commits are different, you can use git log --oneline --decorate --graph --all to check if develop and origin/develop are point the same commit id. Or you can use git branch -D develop and git checkout develop, then make changes on remote repo, and do git fetch again.