Code
# Loop through all subdirectories
for dir in */; do
if [ -d "$dir/.git" ]; then
echo "Pulling in $dir"
cd "$dir"
git pull
cd ..
fi
done批量推送文件夹中的每个 Git 仓库
Jie Hua
Apr 15, 2025
Apr 15, 2025
当在同一个父文件夹下管理多个 Git 仓库时,逐个执行 git pull 或 git push 会非常繁琐。本指南展示如何用简单的 shell 脚本将这些任务自动化。
When working with multiple Git repositories inside a single parent folder, it can be tedious to git pull or git push each one individually. This guide shows you how to automate these tasks using simple shell scripts.
.git 文件夹).git folder)git pull / Step 1: Batch git pull for All Repositories创建一个名为 pull_all.sh 的 shell 脚本:
Create a shell script named pull_all.sh:
git push / Step 2: Batch git push for All Repositories类似地,创建一个名为 push_all.sh 的脚本:
Similarly, create a script called push_all.sh:
只需几行脚本,就能轻松地一次性管理多个 Git 仓库。在更新多个项目时,这种方法有助于节省时间并减少手动操作带来的错误。
With just a few lines of scripting, you can easily manage multiple Git repositories at once. This method helps save time and reduces manual errors when updating multiple projects.