如何批量 git pull 某个文件夹中的 git 仓库?

savokiss -
如何批量 git pull 某个文件夹中的 git 仓库?
上代码

用 shell 脚本可以比较方便实现:

首先新建脚本:pull-all.sh

touch pull-all.sh

填入如下内容:

#!/bin/bash

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
}
# if has param, then use param as path, else tip to input path
if [ -n "$1" ]; then
    getdir $1
else
    read -p "Please input path: " path
    getdir $path
fi

然后改一下权限:

chmod +x pull-all.sh

接下来就可以直接运行了:

./pull-all.sh [要批量 pull 的目录]

也可以不跟参数,会提示你输入目录~

注意这里要输入绝对路径(可以 pwd 获取),否则会只有第一个 pull 成功~

神不神奇~哈哈,上面的代码前半部分是抄的,后半部分是 Copilot 生成的~

食用愉快啦~~

参考文章原文链接如何批量拉取 Git 仓库更新
特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

Tags 标签

shellbackupgit

扩展阅读

加个好友,技术交流

1628738909466805.jpg