git 显示所有分支(包含本地和远程)命令:
git branch -a
git 删除本地分支命令:
git branch -D 本地分支名字
git 显示远程分支命令:
git branch -r
git 删除远程分支命令:
git push origin :bugfix/COP-15
使用管道过滤需要删除的分支:
删除本地分支
git branch |grep 'feature' |xargs git branch -D
删除远程分支:
git branch -r |awk -F '/' '/feature/{printf " %s/%s\n",$2,$3}'|xargs -I {} git push origin :{}
注意:feature是用来过滤远程分支的关键字
例子:
[huangpeng@hpMac:] ~/workspace/javaproj/huangpengProj $ git branch -r |awk '/feature/'
origin/feature/lolo
origin/feature/peng
origin/feature/testDeleteBranch
origin/feature/testPull
[huangpeng@hpMac:] ~/workspace/javaproj/huangpengProj $ git branch -r |awk -F '/' '/feature/{printf " %s/%s\n",$2,$3}'|xargs -I {} git push origin :{}
To http://huangpeng@h.quyiyuan.com/scm/~huangpeng/huangpeng.git
- [deleted] feature/lolo
To http://huangpeng@h.quyiyuan.com/scm/~huangpeng/huangpeng.git
- [deleted] feature/peng
To http://huangpeng@h.quyiyuan.com/scm/~huangpeng/huangpeng.git
- [deleted] feature/testDeleteBranch
To http://huangpeng@h.quyiyuan.com/scm/~huangpeng/huangpeng.git
- [deleted] feature/testPull
[huangpeng@hpMac:] ~/workspace/javaproj/huangpengProj $ git branch -r
origin/dev
origin/master