Git/Shell:批量 git pull,一键更新同一目录下的多个仓库(快速拉取全部项目)

1 篇文章 0 订阅

2020年5月26日 version-2.0

git_pull_Batch.sh

#!/bin/bash

function showGreen(){ echo -e "\033[32m $1 \033[0m"}
function showBlue(){ echo -e "\033[36m $1 \033[0m"}
function showYellow(){ echo -e "\033[33m $1 \033[0m"}
function showWhite(){ echo -e "\033[37m $1 \033[0m"}

function traversal_dir(){
    for sub_dir in `ls $1` #通过 ls root_dir 遍历出子目录,装入子目录 sub_dir 中
    do
        dir=$1"/"$sub_dir #将根目录 $1 与子目录 sub_dir 拼接成完整的目录
        if [ -d $dir ] #判断:是目录的继续下一步
        then
            cd $dir
			showBlue $dir
            showGreen 'git pull '$sub_dir
            git pull
			echo #打印空行
        else
            showYellow $dir
			echo #打印空行
        fi  
    done
}

root_dir="N:\Desktop\qnit" #定义根目录,即项目 project 的上级目录。例如:root_dir/project/.git 
traversal_dir $root_dir 

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HJ3YxoCx-1590483913581)(./images/Git:gitPullBatch version-2.0.png)]

  • 改一下 root_dir 的值就可以用了

2020年1月3日 version-1.0

git_pull_Batch.sh

#!/bin/bash

#输出 git pull xxx 并设置字体颜色为绿色
function showMsg()
 {
   echo -e "\033[32m$1\033[0m"
 }

function getdir(){
    for element in `ls $1`
    do  
        dir_or_file=$1"/"$element
        if [ -d $dir_or_file ]
        then
            cd $1"/"$element 
            showMsg 'git pull '$element
            git pull
        else
            echo $dir_or_file
        fi  
    done
}
root_dir="C:\Users\hp\Desktop\qnit"
getdir $root_dir

在这里插入图片描述

git_pull.sh

#!/bin/bash

echo -e "\033[32mgit pull review\033[0m"
git pull
cmd.exe#阻止窗口关闭
  • 这个就不介绍了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值