Skip to content

Instantly share code, notes, and snippets.

@iamhariomsharma
Created August 9, 2025 11:18
Show Gist options
  • Save iamhariomsharma/1a59b127d74dbbfe041708ce0b7a276a to your computer and use it in GitHub Desktop.
Save iamhariomsharma/1a59b127d74dbbfe041708ce0b7a276a to your computer and use it in GitHub Desktop.
#!/bin/bash
# Path to the configuration file, assumed to be in the root of your project
CONFIG_FILE="SUBMODULE.md"
# Check if configuration file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo "Configuration file not found!"
exit 1
fi
# Function to safely change directories
safe_cd() {
cd "$1" || exit
}
# Read the configuration file and checkout branches
while IFS=':' read -r module branch; do
# Remove any carriage return characters and trim whitespace
module=$(echo "$module" | tr -d '\r\n' | xargs)
branch=$(echo "$branch" | tr -d '\r\n' | xargs)
# Skip empty lines or lines that start with a hash symbol (comments)
if [[ -z "$module" || -z "$branch" || "$module" =~ ^# ]]; then
continue
fi
echo "Checking out to $branch in module $module"
# Check if directory exists before trying to cd into it
if [ ! -d "$module" ]; then
echo "Warning: Directory $module does not exist, skipping..."
continue
fi
safe_cd "$module"
# Fetch latest changes and checkout the branch
git fetch origin || echo "Warning: Failed to fetch from origin for $module"
git checkout "$branch" || {
echo "Error: Failed to checkout branch $branch in $module"
safe_cd -
continue
}
ls -la # Listing detailed directory contents
echo "$module--------------------+---------------"
safe_cd -
done < "$CONFIG_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment