So I was looking for a way to see a list of all the branches that exist on the remote, and found the following 2 commands:
1. git branch -r
2. git remote show origin
Whats the difference between the 2 commands?
So I was looking for a way to see a list of all the branches that exist on the remote, and found the following 2 commands:
1. git branch -r
2. git remote show origin
Whats the difference between the 2 commands?
Copyright © 2021 Jogjafile Inc.
The
git branchcommand looks at (or, invoked differently, modifies) your own repository's information. For remote-tracking branches (git branch -r), this shows what's in your cached copy of what was on the remotes the last time you had your git contact those remotes and get updates.The
git remote show namecommand, by default, runsgit ls-remote, which actually calls up the remote's server over the Internet-phone (or whatever other transport you use) and gets information from it right now. This is what would be put into your cached copy, if you rangit fetch. (Note that if you do rungit fetchafterward, what you get by then could be totally different, since even a few milliseconds can be plenty of time to have massive changes occur. It all depends on how active the remote is.)You can tell
git remote showto use only your cached copy, rather than calling up the remote on the Internet-phone. In this case, the two commands use the same basic information (but present it very differently—git remote showis intended to help you show whatfetchandpushwould do, whilegit branch -rsimply lists what's in your cache).