git 顯示所有分支(包含本地和遠(yuǎn)程)命令:
git branch -a
git 刪除本地分支命令:
git branch -D 本地分支名字
git 顯示遠(yuǎn)程分支命令:
git branch -r
git 刪除遠(yuǎn)程分支命令:
git push origin :bugfix/COP-15
使用管道過濾需要刪除的分支:
刪除本地分支
git branch |grep 'feature' |xargs git branch -D
刪除遠(yuǎn)程分支:
git branch -r |awk -F '/' '/feature/{printf " %s/%s\n",$2,$3}'|xargs -I {} git push origin :{}
注意:feature是用來過濾遠(yuǎn)程分支的關(guān)鍵字
例子:
[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