git ls-remote和git ls-remote origin之间的区别

时间:2018-01-27 00:36:52

标签: git

运行git ls-remotegit ls-remote origin有什么区别?看来git ls-remote输出原始存储库的每个分支和标记的SHA1 ID。由于原始repo默认标题为origin,因此看起来这两个命令产生相同的输出。这是对的吗?

2 个答案:

答案 0 :(得分:6)

虽然the git ls-remote manual page没有提到这一点,但此处的默认参数计算与git fetch, whose documentation is more explicit的默认参数计算相同:

  

如果未指定远程,则默认情况下将使用origin远程,除非为当前分支配置了上游分支。

这意味着,如果您定义了多个遥控器(例如,originsecond),并且您位于B分支上且branch.B.remote设置为{{1现在,在没有任何参数的情况下运行second等同于运行git ls-remote。如果您位于更典型的分支上,git ls-remote second设置为branch.branch.remote或根本未设置,则在未指定特定远程的情况下运行origin相当于运行git ls-remote。< / p>

答案 1 :(得分:3)

你是对的。因为您的遥控器被称为origin,所以两个命令之间没有区别。

要查看所有git遥控器,请运行git remote -v

另一方面,如果你的遥控器被叫foobar,那么git ls-remote origin会给你这个错误:

$ git ls-remote origin
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
相关问题