Skip to content

Instantly share code, notes, and snippets.

  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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
gfo $1
gco -t origin/$1
echo "Unspecified branch name"
Copy link

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