Skip to content

Instantly share code, notes, and snippets.

@jaeyson
Created October 7, 2025 04:37
Show Gist options
  • Save jaeyson/95446ff92e69fda718f00ecd96e7165a to your computer and use it in GitHub Desktop.
Save jaeyson/95446ff92e69fda718f00ecd96e7165a to your computer and use it in GitHub Desktop.
Pull/push all your Git repos Bash script

Process multiple Git repos from top-level script (pull_push_all.sh).

The pull_push_all.sh will perform git pull & push only on main/master branch. And will list any untracked files. Last but not least, the script will give a warning when the current checked-out branch is NOT main or master. That project will be skipped in this case.

The goal of this script is to sync your Git projects with the remote Git server, especially once you got a lot of Git projects.

NOTE 1: This script will NEVER automatically commit changes.

NOTE 2: Processing each repo will take less than 1 second. Efficiently: O(n)

Directory structure

Example:

.
├── pull_push_all.sh
├── project1
│   ├── .git
│   └── README.md
└── project2
    ├── .git
    └── README.md
#!/usr/bin/env bash
# Script that goes through all my git repos and update them. And report any untracked files.
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
NC='\033[0m' # No Color
# Do not add automatically to staged area, but only pull & push all repos
CURRENT="$(dirname "$(realpath "$0")")"
for dir in */;do
cd "$CURRENT/$dir"
echo "INFO: processing ${dir%/}"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ ! -z $BRANCH ]; then
if [[ "$BRANCH" =~ ^(master|main)$ ]]; then
UNTRACKED_FILES=$(git ls-files --others --exclude-standard)
if [ ! -z "$UNTRACKED_FILES" ]; then
echo -e "${ORANGE}WARN:${NC} some files are untracked! List of untracked files:"
echo "$UNTRACKED_FILES"
fi
git pull --quiet && git push --quiet
ret=$?
if [ $ret -ne 0 ]; then
echo -e "${RED}ERROR:${NC} Something went wrong during git pull/push.\n"
else
echo -e "${GREEN}DONE:${NC} ${dir%/} is now up-to-date and pushed successfully."
fi
else
echo -e "${ORANGE}WARN:${NC} Skipping ${dir%/}, current branch is not master or main."
fi
else
echo -e "${ORANGE}WARN:${NC} Skipping ${dir%/}, directory has no git repo."
fi
echo "-----------"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment