Skip to content

Instantly share code, notes, and snippets.

@kodelint
Created October 28, 2016 20:41
Show Gist options
  • Save kodelint/9cc699a79a5b6b35ad464bfce1f420cd to your computer and use it in GitHub Desktop.
Save kodelint/9cc699a79a5b6b35ad464bfce1f420cd to your computer and use it in GitHub Desktop.
Pull latest update for git submodules
#!/bin/bash
APP_PATH=$1
shift
if [ -z $APP_PATH ]; then
echo "Missing 1st argument: should be path to folder of a git repo";
exit 1;
fi
BRANCH=$1
shift
if [ -z $BRANCH ]; then
echo "Missing 2nd argument (branch name)";
exit 1;
fi
echo "Working in: $APP_PATH"
cd $APP_PATH
git checkout $BRANCH && git pull --ff origin $BRANCH
git submodule sync
git submodule init
git submodule update
git submodule foreach "(git checkout $BRANCH && git pull --ff origin $BRANCH && git push origin $BRANCH) || true"
for i in $(git submodule foreach --quiet 'echo $path')
do
echo "Adding $i to root repo"
git add "$i"
done
git commit -m "Updated $BRANCH branch of deployment repo to point to latest head of submodules"
git push origin $BRANCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment