“git remote show origin”: why all branches show “tracked” even when some aren't?

后端 未结 1 977
遥遥无期
遥遥无期 2021-01-03 08:57

Why does \"git remote show origin\" list remote branches as \"tracked\" even when those branches are not linked to a local branch for pull/push? Does \"tracked\" mean someth

相关标签:
1条回答
  • 2021-01-03 09:49

    The "tracked" that git remote show mentions is different from the "tracking" that git branch -vv talks about, that occurs with git checkout -b <branch> <upstream>. (Or maybe "different" is too strong a word, since the underlying idea is the same, it's talking about the remote-tracking branches in your repository, rather than whether you have a local branch that happens to have one of those as its upstream.)

    In particular, git remote show examines the fetch = line(s) for the given remote, and compares this with the references actually available now on the remote (run git ls-remote to see those).

    The default fetch = line for the remote named origin reads:

    fetch = +refs/heads/*:refs/remotes/origin/*
    

    Note the two *s. The one on the left matches all branches that exist on the remote, while the one on the right means "replace with the same name matched on the left".

    Suppose that remote origin currently has the following refs:

    refs/heads/master
    refs/heads/newbr
    refs/tags/v1.2
    refs/notes/commits
    

    Suppose further that branch newbr is new since the last time you cloned, fetched, or otherwise talked to remote origin, so that git branch -r will only list origin/master, not origin/newbr.

    If you now run git remote show origin you will get (along with the other stuff) this bit:

        master tracked
        newbr  new (next fetch will store in remotes/origin)
    

    This means that both branches match, and you already have refs/remotes/origin/master, but you do not yet have refs/remotes/origin/newbr.

    Once you run git fetch, you will acquire origin/newbr. But if, before you do run git fetch, you change your fetch = line so that you won't acquire origin/newbr, git remote show origin will stop mentioning it.

    0 讨论(0)
提交回复
热议问题