删除不再远程的跟踪分支 [英] Remove tracking branches no longer on remote

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

问题描述

是否有一种简单的方法可以删除所有远程等效项不再存在的跟踪分支?

Is there a simple way to delete all tracking branches whose remote equivalent no longer exists?

示例:

分支机构(本地和远程)

Branches (local and remote)

  • 大师
  • 起源/主
  • 起源/错误修复-a
  • 起源/错误修复-b
  • 起源/错误修复-c

在本地,我只有一个 master 分支.现在我需要处理 bug-fix-a,所以我检查它,处理它,并将更改推送到远程.接下来我对 bug-fix-b 做同样的事情.

Locally, I only have a master branch. Now I need to work on bug-fix-a, so I check it out, work on it, and push changes to the remote. Next I do the same with bug-fix-b.

分支机构(本地和远程)

Branches (local and remote)

  • 大师
  • 错误修复-a
  • 错误修复-b
  • 起源/主
  • 起源/错误修复-a
  • 起源/错误修复-b
  • 起源/错误修复-c

现在我有本地分支masterbug-fix-abug-fix-b.Master 分支维护者会将我的更改合并到 master 并删除他已经合并的所有分支.

Now I have local branches master, bug-fix-a, bug-fix-b. The Master branch maintainer will merge my changes into master and delete all branches he has already merged.

所以现在的状态是:

分支机构(本地和远程)

Branches (local and remote)

  • 大师
  • 错误修复-a
  • 错误修复-b
  • 起源/主
  • 起源/错误修复-c

现在我想调用一些命令来删除不再代表的分支(在这种情况下bug-fix-abug-fix-b)在远程存储库中.

Now I would like to call some command to delete branches (in this case bug-fix-a, bug-fix-b), which are no longer represented in the remote repository.

它类似于现有命令git remote prune origin,但更像git local prune origin.

It would be something like the existing command git remote prune origin, but more like git local prune origin.

推荐答案

git remote prune origin 修剪不在远程上的跟踪分支.

git remote prune origin prunes tracking branches not on the remote.

git branch --merged 列出已经合并到当前分支的分支.

git branch --merged lists branches that have been merged into the current branch.

xargs git branch -d 删除标准输入中列出的分支.

xargs git branch -d deletes branches listed on standard input.

小心删除由 git branch --merged 列出的分支.该列表可能包括 master 或您不想删除的其他分支.

Be careful deleting branches listed by git branch --merged. The list could include master or other branches you'd prefer not to delete.

为了让自己有机会在删除分支之前编辑列表,您可以在一行中执行以下操作:

To give yourself the opportunity to edit the list before deleting branches, you could do the following in one line:

git branch --merged >/tmp/merged-branches && 
  vi /tmp/merged-branches && xargs git branch -d </tmp/merged-branches

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

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