Created
September 20, 2025 17:32
-
-
Save jimdiroffii/2640cd6d00c6d835c9655cbea2349315 to your computer and use it in GitHub Desktop.
Pull changes to all repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # The directory containing your git repositories, passed as the first argument. | |
| PARENT_DIR="$1" | |
| # Check if a directory was provided. | |
| if [ -z "$PARENT_DIR" ]; then | |
| echo "β Error: No directory supplied." | |
| echo "Usage: $0 <path/to/your/repos>" | |
| exit 1 | |
| fi | |
| # Check if the provided path is actually a valid directory. | |
| if [ ! -d "$PARENT_DIR" ]; then | |
| echo "β Error: '$PARENT_DIR' is not a valid directory." | |
| exit 1 | |
| fi | |
| # Loop through each item in the parent directory. | |
| for dir in "$PARENT_DIR"/*; do | |
| # Check if the item is a directory AND it contains a .git folder. | |
| if [ -d "$dir/.git" ]; then | |
| echo "-----------------------------------------------------" | |
| # Use basename to get just the folder name from the path. | |
| echo "π Pulling updates for: $(basename "$dir")" | |
| echo "-----------------------------------------------------" | |
| # Run 'git pull' inside a subshell. | |
| # The 'cd' is temporary and won't affect the script's main working directory. | |
| (cd "$dir" && git pull) | |
| echo "" # Add a blank line for readability. | |
| fi | |
| done | |
| echo "β All repositories updated." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment