git cleanup old branches

帅比萌擦擦* 提交于 2019-12-19 08:30:42

问题


I'd like to create a git command that will delete any branches that have all commits included in the current branch e.g.

$ git branch
  groups
* master

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

$ git branch
* master

How would I go about creating this?


回答1:


You can leverage git branch -d here, as it won't delete any branch not yet merged into your current branch:

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

Just tried this locally and it worked, although it is a little terrifying to watch it work.



来源:https://stackoverflow.com/questions/11152339/git-cleanup-old-branches

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!