Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created October 23, 2012 16:50
Show Gist options
  • Save shadowhand/3940027 to your computer and use it in GitHub Desktop.
Save shadowhand/3940027 to your computer and use it in GitHub Desktop.
Fast git branch switcher
#!/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 "$@"
@rkallensee
Copy link

Amazing, thanks a lot! 👍

@chadhamre
Copy link

Love it!

@chadhamre
Copy link

Screen Shot 2020-02-19 at 9 08 43 AM

@chadhamre
Copy link

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