Last active
November 10, 2021 06:29
-
-
Save niksumeiko/76504297c395fedfd2ea66305666ffc4 to your computer and use it in GitHub Desktop.
Git checkout remote branch · ohmyzsh custom alias
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
# ~/.oh-my-zsh/custom/git-checkout-remote-branch-ohmyzsh-alias.zsh | |
unalias gcor | |
function gcor() { | |
if [ -n "$1" ]; then | |
if git show-ref -q --heads $1; then | |
gco $1 | |
else | |
gfo $1 | |
gco -t origin/$1 | |
fi | |
else | |
echo "Unspecified branch name" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use/like CLI (Terminal), are a fan of oh-my-zsh, and oftentimes use
gco
alias to check out a branch, this alias will checkout their/someone else's remote branch from an origin.Executing
gcor feat/SPAYWEB-123
alias will fetch "feat/SPAYWEB-123" branch, switch to it and track upstream to origin automatically. Or, if local branch with this name exists, it's going to switch to it.Voilà, now you have remote branch locally ready 😊