Skip to content

Instantly share code, notes, and snippets.

@tjklemz
Created June 25, 2020 21:47
Show Gist options
  • Save tjklemz/10b92bbf09747763922ba1893e7b661c to your computer and use it in GitHub Desktop.
Save tjklemz/10b92bbf09747763922ba1893e7b661c to your computer and use it in GitHub Desktop.
Git Remote Branch Switcher
#!/usr/bin/env bash
command -v ipt &>/dev/null || npm i -g ipt
git fetch origin
name=$(git branch -r --sort=-committerdate | grep '^\s*origin/' | grep -v 'HEAD' | sed 's/^[[:space:]]*origin\///' | ipt -a -S 20)
if [[ -z "$name" ]]; then
exit 1
fi
if git show-ref --verify --quiet refs/heads/$name ; then
git checkout $name
else
git checkout -t origin/$name
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment