Created
June 11, 2018 13:12
Star
You must be signed in to star a gist
Git Checkout GitHub Remote Branch
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