Git 什么时候刷新远程分支列表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36358265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
When does Git refresh the list of remote branches?
提问by BendEg
回答by centralcmd
To update the local list of remote branches:
要更新远程分支的本地列表:
git remote update origin --prune
To show all local and remote branches that (local) Git knows about
显示(本地)Git 知道的所有本地和远程分支
git branch -a
回答by Tim Biegeleisen
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.
我相信,如果您git branch --all
从 Bash运行,您看到的远程和本地分支列表将反映您在运行命令时本地 Git“知道”的内容。由于您的 Git 始终与系统中的本地分支相关,因此本地分支列表将始终准确。
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 notsee a new remote branch which appeared afterthe last time you fetched or pulled.
但是,对于远程分支,情况并非如此。您的本地 Git 只知道它在上次获取(或拉取)中看到的远程分支。所以这是可能的,你可能会遇到git branch --all
并没有看到一个新的远程分支从而出现后您获取或拉最后一次。
To ensure that your local andremote branch list be up to date you can do a git fetch
beforerunning git branch --all
.
为了确保您的本地和远程分支列表是最新的,您可以git fetch
在运行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 localGit 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.
有关更多信息,运行时出现的“远程”分支git branch --all
根本不是真正的远程;他们实际上是本地人。例如,假设远程调用上有一个分支feature
,您至少将其拉入本地 Git 一次。origin/feature
运行时,您将看到列为分支git branch --all
。但是这个分支实际上是本地的Git 分支。当您这样做时git fetch origin
,此跟踪分支会根据远程的任何新更改进行更新。这就是为什么您的本地状态可能会变得陈旧,因为可能有新的远程分支,或者您的跟踪分支可能会变得陈旧。
回答by Oliver
The OP did not ask for cleanup for all remotes, rather for all branches of default remote.
OP 没有要求对所有遥控器进行清理,而是要求对默认遥控器的所有分支进行清理。
So git fetch --prune
is what should be used.
那么git fetch --prune
应该使用什么。
Setting git config remote.origin.prune true
makes --prune
automatic. In that case just git fetch
will also prune stale remote branches from the local copy. See also Automatic prune with Git fetch or pull.
设置git config remote.origin.prune true
使--prune
自动。在这种情况下,git fetch
只会从本地副本中修剪过时的远程分支。另请参阅使用 Git fetch 或 pull 进行自动修剪。
Note that this does not clean local branches that are no longer tracking a remote branch. See How to prune local tracking branches that do not exist on remote anymorefor that.
请注意,这不会清除不再跟踪远程分支的本地分支。为此,请参阅如何修剪远程不再存在的本地跟踪分支。
回答by vvv
Use git fetch
to fetch all latest created branches.
使用git fetch
获取所有最新创建的分支。
回答by Selman Gun
If you are using Eclipse and want to see new branches from upstream;
如果您正在使用 Eclipse 并希望查看上游的新分支;
In the Git perspective, right click on a Git repository and then choose "Fetch from Upstream". This fetches new remote branches.
在 Git 透视图中,右键单击 Git 存储库,然后选择“从上游获取”。这会获取新的远程分支。