๐ ๏ธ Automating Git Repo Updates and Navigation with a POSIX Shell Script
๐ 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 directly in VS Code
- Work reliably in any POSIX shell (`sh`), not just Bash
Letโs break it down.
๐ The Script
Hereโs the core of the script:
โ๏ธ 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:
- cd /path/to/your/repos - the folder that contains all your cloned repositories
- 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:
Run the script
Run it with an alias
You can add an alias for the script by adding this line to your shell's config file (e.g., .bashrc, .zshrc, or .profile):
Read more about 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!