Last active
January 2, 2016 17:39
-
-
Save Osse/8338536 to your computer and use it in GitHub Desktop.
git dirtyclone
This file contains hidden or 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 | |
# Usage: git dirtyclone <url> [<dir>] | |
if (( $# < 1 || $# > 3 )); then | |
echo 'Usage: git dirtyclone <url> [<dir>]' >&2 | |
exit 1 | |
fi | |
url=$1 | |
if (( $# == 2 )); then | |
dir=$2 | |
mkdir -p "$dir" || exit 1 | |
cd "$dir" | |
fi | |
git init | |
git remote add origin "$url" | |
git fetch origin | |
head=$(git symbolic-ref --short refs/remotes/origin/HEAD) | |
git checkout -b "${head#origin/}" "${head}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment