GIT:删除没有本地跟踪分支的远程分支 [英] GIT: remove remote branches with no local tracking branch

查看:537
本文介绍了GIT:删除没有本地跟踪分支的远程分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说 git branch -a 输出如下内容:

Let's say that git branch -a outputs something like this:


  • A

  • B

  • C

  • * master

  • 远程/ origin / A

  • remotes / origin / B

  • remotes / origin / C

  • remotes / origin / master

  • 远程/来源/ X

  • 远程/来源/ Y

  • 远程处理/来源/ Z

  • A
  • B
  • C
  • *master
  • remotes/origin/A
  • remotes/origin/B
  • remotes/origin/C
  • remotes/origin/master
  • remotes/origin/X
  • remotes/origin/Y
  • remotes/origin/Z

这些分支用粗体显示( X,Y,Z),但我还没有签出它们,甚至没有打算,它们与我不参与的项目有关。

In bold are those branches (X, Y, Z) that are in the remote repository but I have not checked them out yet and I don't even intend to, they are related to a project I don't participate in.

是否有一条命令删除所有没有本地跟踪分支的远程分支(保存在MY存储库中的那些分支,而不是遥控器中的实际远程分支)?

Is there a command to remove all remote branches (those that are saved on MY repository, not the actual remote branch in the remote) which do not have a local tracking branch?

编辑:我打算删除保存在存储库中的远程分支,这表明存在在远程分支。我不想删除遥控器中的实际分支。

Edit: I intend to remove remote branches that are saved in my repository, showing the existence of the branch in the remote. I do not want to remove the actual branches in the remote.

编辑2 :澄清对mattmilten的评论

Edit 2: Clarification in comment to mattmilten

您可以使用 git pull 重新创建所有远程分支,但我并不总是 git pull

You can recreate all remote branches with git pull, but I don't always git pull.

我经常只是 git获取原始主文件ABC ,然后合并或重新设置基础,或者用分支主文件做任何我想做的事情, A,B或C。

I often just git fetch origin master A B C and then merge or rebase or do anything I want with branches master, A, B or C.

点是,每当我 git pull(由于某种原因)时,所有我不想要的分支都会被创建,看来我没有简单的选项可以随后删除它们。

Point is, whenever I "git pull" (for some reason), all the branches I don't want are created and it seems I have no simple option to remove them afterwards.

推荐答案

不,这是不可能的。有关(所有)分支的信息是您回购的一部分,并且在创建新的克隆时将始终被复制。您需要忽略这些分支,或者只运行 git branch 仅列出您的本地分支。

No, this is not possible. The information about (all) branches is a part of your repo and will always be copied when a new clone is created. You need to ignore these branches or simply run git branch to list only your local branches.

您会如何如果您删除有关其存在的信息,是否能够在以后检索远程分支?

How would you be able to retrieve remote branches at a later time, if you delete the information about their existence?

这篇关于GIT:删除没有本地跟踪分支的远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆