Published on : 2025-07-10 17:43
Managing multiple Git repositories for different services or
components can get tedious. Whether you're working on small
personal projects like a blog, a Gemini site, or HTTP
microservices, jumping between directories and pulling the latest
changes manually is a chore.
Thatβs why I wrote a simple, POSIX-compliant shell script to:
* Automatically pull updates from a list of Git repositories
* Provide an interactive menu to open any of them in VS Code
* Work reliably in any POSIX shell (`sh`), not just Bash
Letβs break it down.
- π The Script
#!/bin/sh
# Go to working directory
cd /path/to/your/repos
# List of repositories (folders)
repos="finger gemini gopher http"
# Pull latest changes
for repo in $repos; do
echo "Updating $repo repo"
cd "$repo" && git pull && cd ..
done
# Display repo menu
createmenu() {
while :; do
echo ""
echo "Select a repo to open:"
echo "---------------------------"
i=1
for repo in $repos; do
echo "$i) $repo"
i=$((i + 1))
done
echo "$i) Exit"
printf "Enter your choice (1-$i): "
read choice
case $choice in
''|*[!0-9]*)
echo "Invalid input: please enter a number."
continue
;;
esac
if [ "$choice" -eq "$i" ]; then
echo "Exiting..."
exit
elif [ "$choice" -ge 1 ] && [ "$choice" -lt "$i" ]; then
j=1
for repo in $repos; do
if [ "$j" -eq "$choice" ]; then
echo "Opening $repo..."
cd "$repo" && code .
exit
fi
j=$((j + 1))
done
else
echo "Please select a number from 1 to $i."
fi
done
}
createmenu
- βοΈ What It Does
* Batch git pull - It loops over your list of repositories and
runs git pull in each. Great for keeping all your local copies up
to date.
* Interactive Menu - After updating, it presents a numbered menu
to select one of the repos. Once selected, it uses code . to open
that directory in Visual Studio Code.
* Exit Option & Input Validation - You can cleanly exit by
choosing the last number. It re-prompts if you enter an invalid
number or non-numeric input β no crashing, no surprises.
- π§ Why POSIX sh?
While Bash offers features like arrays and select, I wanted this
script to run in any Unix-like environment, including:
* Alpine-based Docker containers
* Minimal CI systems
* macOS (which defaults to sh for scripts)
* Embedded or limited-resource environments
This means no Bash-isms β just pure POSIX sh, making it portable
and dependable.
- π How To Use
Save the script as update-git-repos.sh
-- Edit variables
You have to edit only 2 things at the top of the script:
# Go to working directory
cd /path/to/your/repos - the folder that contains all your
cloned repositories
# List of repositories (folders)
repos="finger gemini gopher http" - list of folders/
repositories you want to update/pull - this should be located
in the folder set above
-- Make it executable:
chmod +x update-git-repos.sh
./update-git-repos.sh
You can add an alias for the script by adding this line to your
shell's config file (e.g., .bashrc, .zshrc, or .profile):
alias update-repos='/full/path/to/update-git-repos.sh'
(DIR) Using aliases for complex and daily terminal commands
π‘ Final Thoughts
This script has been a small but helpful productivity boost for
juggling multiple personal projects. It saves time, avoids
repetitive commands, and keeps everything in sync. And because
it's written in portable sh, it'll run practically anywhere.
If you find this useful, feel free to adapt it to your own
workflow:
* Tie it into your dotfiles,
* Or make it open editors other than VS Code.
The point is: let your tools work for you.
Happy hacking!
(DIR) Back to my phlog