git branch -r vs git remote show origin

﹥>﹥吖頭↗ 提交于 2019-12-11 20:02:48

问题


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?


回答1:


The git branch command 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 name command, by default, runs git 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 ran git fetch. (Note that if you do run git fetch afterward, 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 show to 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 show is intended to help you show what fetch and push would do, while git branch -r simply lists what's in your cache).



来源:https://stackoverflow.com/questions/27068739/git-branch-r-vs-git-remote-show-origin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!