diff options
Diffstat (limited to 'git-clone-or-pull')
-rwxr-xr-x | git-clone-or-pull | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/git-clone-or-pull b/git-clone-or-pull new file mode 100755 index 0000000..f2575c2 --- /dev/null +++ b/git-clone-or-pull @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# Handy single command to clone or pull a repository +# + +# Parameters +BASENAME="`basename $0`" +ORIGIN="$1" +DEST="$2" + +# Check +if [ -z "$DEST" ]; then + echo "usage: $BASENAME <origin> <dest>" + exit 1 +fi + +# Dispatch +if [ ! -e "$DEST" ]; then + echo "Cloning $ORIGIN into $DEST..." + git clone $ORIGIN $DEST +else + echo "Updating $DEST..." + git -C $DEST pull + + # Alternate approach, that restore any existing changes + #( + # cd $DEST &> /dev/null + # git restore . + # git pull + #) +fi + +# Exit +exit $? |