Last active
December 21, 2015 23:38
-
-
Save jdpaton/6383313 to your computer and use it in GitHub Desktop.
Clones or updates and checks out the appropriate branch while checking for existence of either.
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
#!/bin/bash | |
TARGET_DIR=${1:-"./new-repo"} | |
BRANCH=${2:-"master"} | |
REPO=${3:-"git://repo/name.git"} | |
if [ -e "${TARGET_DIR}" ] | |
then | |
pushd $TARGET_DIR | |
git fetch | |
exists=$(git show-branch $BRANCH > /dev/null 2>&1; echo $?) | |
if [ "$exists" == "0" ] | |
then | |
git checkout $BRANCH | |
else | |
git checkout -b $BRANCH origin/$BRANCH | |
fi | |
git reset --hard origin/$BRANCH | |
popd | |
else | |
git clone $REPO $TARGET_DIR | |
fi | |
pushd $TARGET_DIR | |
git show | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment