來一個批量刪除 git 遠程分支的 shell 腳本


  由於一次特殊原因,要求刪除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";

 

  這樣,每次都會提示你要刪除的分支!

  你就負責點確認就行了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM