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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:04:34  来源:igfitidea点击:

When does Git refresh the list of remote branches?

gitgithubbranchremote-branch

提问by BendEg

Using git branch --allshows all remoteand localbranches. When does Git refresh this list?

Usinggit branch --all显示所有远程本地分支。Git 什么时候刷新这个列表?

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

在拉/推?以及如何使用Git Bash刷新它?

回答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 --allfrom 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 --alland 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 fetchbeforerunning git branch --all.

为了确保您的本地远程分支列表是最新的,您可以git fetch运行git branch --all.

For further information, the "remote" branches which appear when you run git branch --allare not really remote at all; they are actually local. For example, suppose there be a branch on the remote called featurewhich you have pulled at least once into your local Git. You will see origin/featurelisted 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 --pruneis what should be used.

那么git fetch --prune应该使用什么。

Setting git config remote.origin.prune truemakes --pruneautomatic. In that case just git fetchwill 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 fetchto 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 存储库,然后选择“从上游获取”。这会获取新的远程分支。

回答by markthegrea

If you are using Eclipse,

如果您使用的是 Eclipse,

  1. Open "Git Repositories"
  2. Find your Repository.
  3. Open up "Branches" then "Remote Tracking".
  1. 打开“Git 存储库”
  2. 找到您的存储库。
  3. 打开“分支”,然后打开“远程跟踪”。

Git

吉特

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

他们应该都在里面。右键单击并“结帐”。