BASH

Automate Git Pull & Status for Multiple Repos

Streamline your workflow by automating `git pull` and checking the status across multiple Git repositories in different directories with a single Bash script.

#!/bin/bash

# Define the base directory where your repositories are located
BASE_DIR="/path/to/your/projects"

# Array of repository directory names (subdirectories of BASE_DIR)
REPOS=("my-frontend-app" "my-backend-api" "shared-components")

echo "--- Starting Git Operations ---"

for REPO in "${REPOS[@]}"; do
    REPO_PATH="$BASE_DIR/$REPO"
    if [ -d "$REPO_PATH" ]; then
        echo "
--- Processing Repository: $REPO ---"
        cd "$REPO_PATH" || {
            echo "Error: Could not change directory to $REPO_PATH"
            continue
        }

        echo "Pulling latest changes..."
        git pull

        echo "Checking repository status..."
        git status --short
        echo "------------------------------"
    else
        echo "Warning: Repository directory not found: $REPO_PATH"
    fi
done

echo "
--- All Git Operations Complete ---"
How it works: This script automates common Git tasks across multiple repositories. It iterates through a list of directory names, changes into each repository's path, executes `git pull` to fetch and merge the latest changes from the remote, and then runs `git status --short` to display any local modifications. This is highly useful for developers managing several interconnected projects, ensuring all are up-to-date with minimal manual intervention.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs