-
-
Save chadhamre/e33637574566bcfe337cdbfb97dbf8d6 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 branch-pick" | |
} | |
version() { | |
echo "gitBranchPick v0.1.0" | |
} | |
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 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To add this script to OSX:
Step 1: Copy this file to
/Users/<xxxxxx>/bin
Step 2: Configure your shell to load bin by adding the following to your
.zshrc
config:# load bin folder
export PATH=$PATH:/Users/chadhamre/bin
Step 3: Make the file executable by running:
sudo chmod +x git-branch-pick