Git:如何列出正在跟踪不再存在的远程分支的本地分支?
如何列出出现的任何本地分支(按照 .git / config
)要跟踪不再存在的远程分支?在这种情况下,远程分支机构在GitHub上,但我怀疑它们的位置没有关系。
How can I list any local branches that appear (as per .git/config
) to be tracking remote branches that no longer exist? Remote branches are on GitHub in this case but I suspect their location has no relevance.
例如:
For example:
- 我有本地分行,
a
,b
,c
和d
。 -
a
code> origin / a 和c
正在追踪origin / c
。 -
b
和d
不会跟踪远程分支。 b $ b -
origin / a
已被合并回master,并在清理资料库时被删除;我不再需要保留本地分行a
。 - 如果本地分行
a
检出到工作树,运行git fetch
或git pull
导致错误您的配置指定从远程合并ref'a',但不会提取这样的ref。
- I have local branches,
a
,b
,c
andd
. -
a
is trackingorigin/a
andc
is trackingorigin/c
. -
b
andd
are not tracking remote branches. -
origin/a
has been been merged back into master and was deleted during a repository clean-up; I no longer need to keep local brancha
. - If local branch
a
is checked out to the working tree, runninggit fetch
orgit pull
results in the errorYour configuration specifies to merge with the ref 'a' from the remote, but no such ref was fetched.
我如何生成仅包含 a
以及任何其他似乎正在跟踪不再存在的远程分支的本地分支?
How would I produce the list containing only a
and any other local branches that appear to be tracking remote branches that no longer exist?
我想识别这些,以便我可以删除不再需要的过时本地分行。
I would like to identify these so that I can delete obsolete local branches I no longer need.
列表不应包含本地分行 b
或 d
不跟踪远程分支,也不是 c
正在跟踪 origin / c
,它仍然存在。
The list should not include local branches b
or d
that are not tracking remote branches, and also not c
that is tracking origin/c
, which still exists.
如果您的本地分行正在跟踪远程分行,您可以过滤分行列表以便显示那些没有跟踪分支的人:
If your local branches are tracking the remote branch you can filter the list of branches so show the ones that do not have a tracking branch with:
git branch -vv | grep -v origin
这将提供关于分支上的最后一次提交的额外信息,但您可以过滤掉
This will provide some extra information about the last commit that is on the branch but you can filter that out
git branch -vv | grep -v origin | awk '{print $1}'
这将只打印未跟踪的分支的名称一个远程分支。
This will only print the name of the branch that isn't tracking a remote branch.