Created
October 23, 2012 16:50
-
-
Save shadowhand/3940027 to your computer and use it in GitHub Desktop.
Fast git 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
#!/bin/bash | |
usage() { | |
echo "usage: git switchbranch" | |
} | |
version() { | |
echo "switchbranch v0.0.2" | |
} | |
select_branch() { | |
# Set the prompt string | |
PS3="--> Select a branch? " | |
# first branch is always "master" | |
branches=("master $(git branch | sed -e 's/*//' -e 's/(no branch)//' -e 's/master//')") | |
select selected in $branches; do | |
if [ "$selected" == "quit" -o "$selected" == "q" -o "$selected" == "" ]; then | |
exit 1 | |
fi | |
git checkout "$selected" | |
exit 0 | |
done | |
} | |
main() { | |
command="$1" | |
shift | |
case $command in | |
"version") version;; | |
*) select_branch "$@";; | |
esac | |
} | |
main "$@" |
Amazing, thanks a lot! 👍
Love it!
I renamed mine to git pick-branch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome, thanks! Jammed it in my bashrc and am living the good life