批量拉取指定目录下的所有Git项目

系统划分越来越细,模块越来越多,想要排除一个问题,需要拉取N多个模块代码!太烦人了!

一键拉取指定目录下所有的Git的最新代码

 

#!/bin/bash

function gpull ()
{
    cd $1
    #pwd
    git checkout master
    git pull
}

function isGitDir ()
{
    if [ -d $1 ]; then 
        echo $(find $1 -maxdepth 1 -name .git)
    fi
}

function findGitAndPull()
{
    #echo $1
    gitDir=$(isGitDir $1)
    #echo "gitDir: "$gitDir
    if [ -n "$gitDir" ]; then
        echo -e "\e[1;32m当前目录是个Git目录,拉取最新代码:\e[0m"$1
        gpull $1
    else
        echo -e "\e[1;31m当前目录不是Git目录,开始处理其子文件:\e[0m"$1
        for fileName in $(ls $1)
        do
            currentName=$1"/"$fileName
            echo -e "\e[1;31m子文件名称:\e[0m"$currentName
            if [ -d $currentName ]; then
                echo -e "\e[1;31m子文件是个目录,递归处理:\e[0m"$currentName
                findGitAndPull $currentName
            else 
                echo -e "\e[1;31m子文件不是目录,直接忽略:\e[0m"$currentName
            fi
        done
    fi
}

findGitAndPull $1

 

 

再搞个 alias 参数直接写死你的代码目录

 

 

posted @ 2022-06-26 16:26  halu126  阅读(971)  评论(0编辑  收藏  举报