Git Push every repo in a folder

Bash
Author

Jie Hua

Published

April 15, 2025

Modified

April 15, 2025

Introduction

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.

Prerequisites

  • A Unix-like shell (Linux/macOS or Git Bash on Windows)
  • Git installed and configured
  • All subdirectories must be Git repositories (i.e., each one has a .git folder)

Step 1: Batch git pull for All Repositories

Create a shell script named pull_all.sh:

# Loop through all subdirectories
for dir in */; do
  if [ -d "$dir/.git" ]; then
    echo "Pulling in $dir"
    cd "$dir"
    git pull
    cd ..
  fi
done

Step 2: Batch git push for All Repositories

Similarly, create a script called push_all.sh:

# Loop through all subdirectories
for dir in */; do
  if [ -d "$dir/.git" ]; then
    echo "Pushing in $dir"
    cd "$dir"
    git add .
    git commit -m "Auto commit"
    git push
    cd ..
  fi
done

Conclusion

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.