Skip to content

Instantly share code, notes, and snippets.

@Osse
Last active January 2, 2016 17:39
Show Gist options
  • Save Osse/8338536 to your computer and use it in GitHub Desktop.
Save Osse/8338536 to your computer and use it in GitHub Desktop.
git dirtyclone
#!/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