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

Bar*_*tek 5 git github

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

git fetch
git branch -a 
Run Code Online (Sandbox Code Playgroud)

显示执行时不可见的远程分支

git ls-remote --heads origin
Run Code Online (Sandbox Code Playgroud)

这种行为的原因是什么?

[澄清]

(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
Run Code Online (Sandbox Code Playgroud)

Tim*_*sen 5

运行git branch -a列出您机器上的所有本地和跟踪分支,它们都存在于本地。这是我跑步时得到的git branch -a

master
branch1
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/branch1
Run Code Online (Sandbox Code Playgroud)

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

b9e515799... refs/heads/master
9a7faebd1... refs/heads/branch1
Run Code Online (Sandbox Code Playgroud)

存储库只有真正的远程分支,当您使用git pull.