When does git refresh the list of remote branches?

删除回忆录丶 提交于 2019-11-29 18:31:35
centralcmd

To show all local and remote branches that (local) git knows about

git branch -a

To update the local list of remote branches:

git remote update origin --prune

I believe that if you run git branch --all from the 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.

The OP did not ask for cleanup for all remotes, rather for all branches of default remote.

So git fetch --prune is what should be used.

Setting git config remote.origin.prune true makes --prune automatic, in that case just git fetch will also prune stale remote branches from local copy. See also Automatic prune with git fetch or pull.

Note that this does not clean local branches that are no longer tracking a remote branch. See https://stackoverflow.com/a/54484443/869951 for that.

vvv

Use git fetch to fetch all latest created branches.

If you are using Eclipse and want to see new branches from upstream;

In Git perspective right click on git repository and then choose "Fetch from Upstream". This fetches new remote branches.

If you are using Eclipse,

  1. Open "Git Repositories"
  2. Find your Repository.
  3. Open up "Branches" then "Remote Tracking".

They should all be in there. Right click and "checkout."

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