Created
March 8, 2018 03:03
-
-
Save aduth/868f08b958312243ba68cf828b90b9f0 to your computer and use it in GitHub Desktop.
Checkout from GitHub remote via `user:branch` syntax
This file contains 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 | |
# https://stackoverflow.com/a/26843249/995445 | |
IFS=':' read -ra parts <<< "$1" | |
if [ ${#parts[@]} == 1 ]; then | |
branch=${parts[0]} | |
else | |
remote=${parts[0]} | |
branch=${parts[1]} | |
fi | |
# https://stackoverflow.com/a/26843249/995445 | |
if [[ -n $remote ]] && ! git config remote.${remote}.url > /dev/null; then | |
url=$( git config remote.origin.url | sed -e "s#github\.com/[^/]*#github.com/"$remote"#g" ) | |
git remote add $remote $url | |
git fetch $remote | |
fi | |
git checkout $branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment