Skip to content

Instantly share code, notes, and snippets.

@nicferrier
Created April 1, 2012 19:34
Show Gist options
  • Star 59 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nicferrier/2277987 to your computer and use it in GitHub Desktop.
Save nicferrier/2277987 to your computer and use it in GitHub Desktop.
Clone a git repo if it does not exist, or pull into it if it does exist
#!/bin/sh
REPOSRC=$1
LOCALREPO=$2
# We do it this way so that we can abstract if from just git later on
LOCALREPO_VC_DIR=$LOCALREPO/.git
if [ ! -d $LOCALREPO_VC_DIR ]
then
git clone $REPOSRC $LOCALREPO
else
cd $LOCALREPO
git pull $REPOSRC
fi
# End
@jotaelesalinas
Copy link

I made this script, a "little bit" more complex but which fulfilled my specific needs: https://gist.github.com/jotaelesalinas/cc88af3c9c4f8664216ea07bd08c250f

@sugatoray
Copy link

git clone "$REPOSRC" "$LOCALREPO" 2> /dev/null || (cd "$LOCALREPO" ; git pull)

Thank you. 👍

@ZeekDaGeek
Copy link

No need to cd into the directory to pull from it. git -C "$LOCALREPO" pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment