Skip to content

Instantly share code, notes, and snippets.

@adrenalinkin
Last active December 1, 2017 11:15
Show Gist options
  • Save adrenalinkin/2fba78988271f4cfe1c825760fcd6242 to your computer and use it in GitHub Desktop.
Save adrenalinkin/2fba78988271f4cfe1c825760fcd6242 to your computer and use it in GitHub Desktop.
Batch git submodule sync by received branch name
#!/bin/bash
set -e
RES=$(echo -en '\033[0m')
RED=$(echo -en '\033[00;31m')
GREEN=$(echo -en '\033[00;32m')
YELLOW=$(echo -en '\033[00;33m')
root=$PWD
# Ask the user for branch name
read -p 'Branch name: ' branchName
echo -e "\nBranch ${GREEN}$branchName${RES}\n"
echo -e "\nBranch has been reached for ${GREEN}$root${RES}"
git checkout $branchName || true
git pull
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
currentPath="$root/$path"
cd $currentPath
echo -e "\nBranch has been reached for submodule ${GREEN}$path${RES}"
git checkout $branchName || true
git pull
cd $root
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment