Created
June 3, 2015 19:42
-
-
Save jasisk/5d6fbdc9d922925d842e to your computer and use it in GitHub Desktop.
automatically checkout a remote's "default" branch
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
#!/usr/bin/env sh | |
# Automatically checkout a local branch that tracks whatever the remote's | |
# HEAD is defined as (aka, the "default" branch). | |
# | |
# Place this somewhere on your PATH and call it with: | |
# $ git auto-checkout [remote] | |
# | |
# Takes an optional argument specifying which remote (defaults to origin). | |
# Note that if the branch already exists, it will be reset to the HEAD | |
# of [remote]/[branch]. | |
REMOTE=${1:-origin} | |
git fetch $REMOTE | |
[ $? -eq 0 ] || exit 1 | |
git remote set-head $REMOTE -a | |
BRANCH=`git symbolic-ref --short refs/remotes/$REMOTE/HEAD | cut -d/ -f2-` | |
git checkout -B $BRANCH -t $REMOTE/$BRANCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment