简体   繁体   中英

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?

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 (eg, 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 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 .

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.

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