简体   繁体   中英

git branch is messed up

I have a local repository cloned from a remote one. When I do:

git branch -a

I get:

* add-real-testcases
  couchdb_1.1.0
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/couchdb_1.1.0

Now, I think this is not correct. I was expecting something like:

  couchdb_1.1.0 -> origin/couchdb_1.1.0

Since my couchdb_1.1.0 branch is tracking a remote branch (I just pushed to it, without extra info). So I go and I check my .git/config :

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git@myhost.com:my_repo.git
[branch "master"]
        remote = origin
        merge = refs/heads/master
[branch "couchdb_1.1.0"]
        remote = origin
        merge = refs/heads/couchdb_1.1.0

The tracking info is there, as I expected. But git branch -a is not showing it.

I got to this situation probably because I have been creating and deleting local and remote branches. So I try to solve this reporting issue by setting the upstream manually (even though it is already set in the config , but anyway ...)

$ git branch couchdb_1.1.0 --set-upstream origin/couchdb_1.1.0
Branch couchdb_1.1.0 set up to track remote branch couchdb_1.1.0 from origin.

But git branch -a is still not showing it.

I though git branch was getting the info from .git/config , but somehow it is not. Or maybe I am confused about what the -> syntax in git branch -a means?

You are misinterpreting the output of git branch -a . git branch is not showing you information about which remote branches your local branches are tracking you it is just showing you which branches are "symbolic refs" to other branches.

In this case origin's HEAD is a symbolic ref to master on origin. This is just telling you that the default (or for non-bare repositories the checked-out) branch on origin is master .

Try git branch -vv to see the tracking relationships of your local branches.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM