matsuo_basho
matsuo_basho

Reputation: 3020

Difference between git ls-remote and git ls-remote origin

What is the difference between running git ls-remote and git ls-remote origin? It appears git ls-remote outputs the SHA1 IDs of each branch and tag of the original repository. Since the original repo is by default titled origin, it appears that these two commands yield the same output. Is this correct?

Upvotes: 7

Views: 26002

Answers (2)

torek
torek

Reputation: 488183

Although the git ls-remote manual page fails to mention this, the default argument computation here is the same as that for git fetch, whose documentation is more explicit:

When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch.

What this means is that if you have multiple remotes defined (e.g., origin and second) and you are on branch B with branch.B.remote set to second, running git ls-remote without any arguments is now equivalent to running git ls-remote second. If you are on a more typical branch, with branch.branch.remote set to origin or not set at all, running git ls-remote without specifying a particular remote is equivalent to running git ls-remote origin.

Upvotes: 9

ACVM
ACVM

Reputation: 1527

You're correct. Because your remote is called origin there's no difference between the two commands.

To see all your git remotes, run git remote -v.

On the other hand, if your remote was called foobar then git ls-remote origin would give you this error:

$ 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.

Upvotes: 6

Related Questions