git 清理旧分支

标签 git git-bash

我想创建一个 git 命令来删除当前分支中包含所有提交的任何分支,例如

$ git branch
  groups
* master

$ git cleanup-branches
deleted groups # all commits are included in master

$ git branch
* master

我将如何着手创建它?

最佳答案

您可以在此处利用 git branch -d,因为它不会删除任何尚未 merge 到您当前分支的分支:

git config --global alias.cleanup-branches \
'!git branch | grep -v "\*" | awk "{ print $1 }" | xargs git branch -d'

只是在本地尝试了这个并且它起作用了,尽管看着它起作用有点可怕。

关于git 清理旧分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11152339/

相关文章:

git - 有没有一种简单的方法可以删除未跟踪的 git 文件

git bash 配置问题

git - 如何使使用 git bash(触摸文件)创建的文件在 Windows 8.1 中可见?

git - 每次更新通过 git 可用的包时,我是否需要发布到 npm?

git - 如果依赖项尝试从 Internet 下载,如何配置代理?

git - 发布补丁队列的 Git 方法是什么?

git - 跟踪所有远程 git 分支作为本地分支

git - curl : (35) Server aborted the SSL handshake in Mac OS X El Capitan (10. 11.4)

amazon-web-services - 如何在 Windows 上获取适用于 AWS CLI 的 AWS_Completer?

git: 'credential-cache' 不是 git 命令