由于一次特殊原因,要求删除n个项目的除master及特定分支外的所有分支,而在 gitblit 上也不好操作,只好借助 git 客户端操作了!
然而客户端只能一个分支一个分支地删除,着实烦人!
于是写了shell,可能你也有用得上的时候呢~!
#!/bin/bash # 批量删除远程分支 shell script reponsitory_name="$1" cd $reponsitory_name; echo " -R welcome the 【$reponsitory_name】 reponsitory, you will delete the branches, WARNNING !!! "; echo " -R !!! WARNNING !!! "; all_branches=`git branch -a`; #echo $all_branches; for br1 in $all_branches; do br1_simple_name=`echo $br1 | grep '/' | cut -d '/' -f3` if [[ "" != "$br1_simple_name" && "HEAD" != "$br1_simple_name" && "master" != "$br1_simple_name" ]]; then echo " -D begin delete branch " $br1 " --->> " $br1_simple_name; read -p " -W Are you sure delete the branch ** $br1 (y/n)[n]: " answer if [[ "$answer" = "Y" || "${answer}" = "y" ]]; then echo " Yes! deleting branch $br1 -> $br1_simple_name"; git push origin --delete $br1_simple_name; else echo " Skipped!!!"; fi; fi; done; echo "over";
这样,每次都会提示你要删除的分支!
你就负责点确认就行了!