多个 git 仓库同时切换分支的脚本

需要系统支持 whiptail 命令。

#!/bin/bash
PWD=$pwd

# 查看git状态
function check_git_status() {
  if [[ -n $(git status -s) ]]; then
    echo -ne '\033[1;31m [x] \033[0m'
    echo $PWD
    exit 1
  fi
}

# 检查目录状态
function check_dir_status() {
  cd ~/ipc/mkfirmware/web && check_git_status
  cd ~/ipc/mkfirmware/motu && check_git_status
  cd ~/ipc/mkfirmware/packshop_hi3516cv500 && check_git_status
  cd ~/ipc/mkfirmware/packshop_ssc336q && check_git_status
  cd ~/ipc/mkfirmware/packshop_ssc337 && check_git_status
  cd ~/ipc/mkfirmware/packshop_gk7205v200 && check_git_status
  cd ~/ipc/mkfirmware/firmware && check_git_status
}
check_dir_status

OPTION=$(
  whiptail --title "Menu Dialog" --menu "Select branch." 15 60 7 \
    "1" "master" \
    "2" "saidav1" \
    "3" "khj" \
    "4" "safesoft" \
    "5" "andlinkpc1" \
    "6" "saida_ahdx" \
		"7" "gkxj" 3>&1 1>&2 2>&3
)

exitstatus=$?
if [ $exitstatus != 0 ]; then
  echo "Cancel."
  exit 1
fi

function Switch() {
  case $OPTION in
  1)
    branch=master
    ;;

  2)
    branch=saidav1
    ;;

  3)
    branch=khj
    ;;

  4)
    branch=safesoft
    ;;

  5)
    branch=andlinkpc1
    ;;

  6)
    branch=saida_ahdx
    ;;

  7)
    branch=gkxj
    ;;

  *)
    exit 1
    ;;
  esac

  echo -e "\033[1;36mSwitch to $branch.\033[0m"
  cd ~/ipc/mkfirmware/web && pwd && git switch $branch && echo -e "\n"
  cd ~/ipc/mkfirmware/motu && pwd && git switch $branch && echo -e "\n"
  cd ~/ipc/mkfirmware/packshop_hi3516cv500 && pwd && git switch $branch && echo -e "\n"
  cd ~/ipc/mkfirmware/packshop_ssc336q && pwd && git switch $branch && echo -e "\n"
  cd ~/ipc/mkfirmware/packshop_ssc337 && pwd && git switch $branch && echo -e "\n"
  cd ~/ipc/mkfirmware/packshop_gk7205v200 && pwd && git switch $branch && echo -e "\n"
  cd ~/ipc/mkfirmware/firmware && pwd && git switch $branch && echo -e "\n"
}
Switch

多个 git 仓库同时切换分支的脚本
https://leec.me/b901b5dd8f92/
作者
Leec
发布于
2020年8月9日
更新于
2022年6月21日
许可协议