Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoomon/9177ff2080ba06a2a73acdd9f11b8c16 to your computer and use it in GitHub Desktop.
Save qoomon/9177ff2080ba06a2a73acdd9f11b8c16 to your computer and use it in GitHub Desktop.
Git clone into non-empty directory
#!/bin/sh
REPO_URL="$1"
TARGET_DIR="${2:-$(basename $REPO_URL .git)}"
SHADOW_DIR='.git.shadow'
cd $TARGET_DIR
git clone --no-checkout $REPO_URL $SHADOW_DIR
mv $SHADOW_DIR/.git .
rm -rf $SHADOW_DIR
git reset HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment