Last active
October 15, 2019 06:10
-
-
Save wilensky/aafe1c09ae0edb2897bd74f051553f4a to your computer and use it in GitHub Desktop.
Script checkouts each submodule on a given branch if latter exists (or fallback branch is used) and pulls if behind
This file contains 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
#!/usr/bin/env bash | |
fetch=$(git fetch); | |
if [ "$(git show-ref refs/remotes/origin/$1)" ]; then # Checking branch for existence on remote | |
co=$(git checkout "$1"); # Checkouting branch that we checked for existence above | |
else | |
defaultFb="master"; # Default fallback | |
fb=${2:-$defaultFb} # Resulting fallback | |
echo "- Branch $1 does not exist. Switching to ${fb}"; | |
co=$(git checkout $fb); # Checkouting fallback branch | |
fi | |
echo "$co"; # Showing output for consistency | |
if [[ $co == *"can be fast-forwarded"* ]]; then # Checking if we are behind the checkouted branch | |
echo "$(git pull)"; # Performing `pull` | |
fi | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation
Wherever you are execute
Usage