When does Git refresh the list of remote branches?

后端 未结 5 591
清歌不尽
清歌不尽 2021-01-29 17:04

Using git branch --all shows all remote and local branches. When does Git refresh this list?

On pull/push? And how do I refresh it using G

5条回答
  •  佛祖请我去吃肉
    2021-01-29 17:37

    I believe that if you run git branch --all from Bash that the list of remote and local branches you see will reflect what your local Git "knows" about at the time you run the command. Because your Git is always up to date with regard to the local branches in your system, the list of local branches will always be accurate.

    However, for remote branches this need not be the case. Your local Git only knows about remote branches which it has seen in the last fetch (or pull). So it is possible that you might run git branch --all and not see a new remote branch which appeared after the last time you fetched or pulled.

    To ensure that your local and remote branch list be up to date you can do a git fetch before running git branch --all.

    For further information, the "remote" branches which appear when you run git branch --all are not really remote at all; they are actually local. For example, suppose there be a branch on the remote called feature which you have pulled at least once into your local Git. You will see origin/feature listed as a branch when you run git branch --all. But this branch is actually a local Git branch. When you do git fetch origin, this tracking branch gets updated with any new changes from the remote. This is why your local state can get stale, because there may be new remote branches, or your tracking branches can become stale.

提交回复
热议问题