Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niksumeiko/76504297c395fedfd2ea66305666ffc4 to your computer and use it in GitHub Desktop.
Save niksumeiko/76504297c395fedfd2ea66305666ffc4 to your computer and use it in GitHub Desktop.
Git checkout remote branch · ohmyzsh custom alias
# ~/.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
}
@niksumeiko
Copy link
Author

niksumeiko commented Apr 27, 2020

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 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment