-
-
Save tjklemz/10b92bbf09747763922ba1893e7b661c to your computer and use it in GitHub Desktop.
Git Remote Branch Switcher
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
#!/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