git批量删除已合并的远程分支

# Make sure remotes are up to date (with stale remotes purged):
# 先执行远程获取
git fetch -p
 
# Initial no-op run --- do the branches to delete look correct?
# Be careful to omit 'master' from the output.
# grep -v 用于排除关键字,检查此命令输出的branch名字是否合理,调整次命令直至筛选出需要删掉的branch
# "git branch --remote"每行输出以“origin/”开头,命令"cut -b 10-"用于删除此前缀
git branch --remote --merged origin/master | grep -v 'master' | cut -b 10- | xargs

# Do the bulk delete!!!  (can take a long time...)
# 执行远程删除,务必确保之前的待删除branch筛选合理!
git branch --remote --merged origin/master | grep -v 'master' | cut -b 10- | xargs git push --delete origin

相关推荐