列出远程分支 - git branch -a vs git ls-remote --heads origin

时间:2017-11-03 09:14:39

标签: git github

以下post命令应该产生与远程分支相同的输出,但是

git fetch
git branch -a 

显示执行

时不可见的远程分支
git ls-remote --heads origin

这种行为的原因是什么?

[澄清]

(TA216441) $ git pull
Your configuration specifies to merge with the ref 'refs/heads/TA216441'
from the remote, but no such ref was fetched.

(TA216441) $ git fetch
(TA216441) $ git branch -a
* TA216441
  TA216442
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/TA212425
  remotes/origin/TA216441
  remotes/origin/TA219346
  remotes/origin/TA220305
  remotes/origin/TA223738
  remotes/origin/master

(TA216441) $ git ls-remote --heads origin
  hash-1 refs/heads/DE18756_2
  hash-2 refs/heads/TA212425
  hash-2 refs/heads/TA219346
  hash-3 refs/heads/TA220305
  hash-4 refs/heads/master

1 个答案:

答案 0 :(得分:2)

运行git branch -a会在您的计算机上列出所有本地和跟踪分支,这两个分支都存在于本地本地。这是我跑git branch -a时得到的:

master
branch1
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/branch1

但是当您运行git ls-remote --heads origin时,它会在您的仓库中列出远程头部引用。对于同一个回购,这就是我所看到的:

b9e515799... refs/heads/master
9a7faebd1... refs/heads/branch1

repo只有真正的远程分支,当您使用git pull之类的东西时,这就是您实际同步的。