Skip to content

Instantly share code, notes, and snippets.

@chadhamre
Forked from shadowhand/git-switchbranch
Last active April 20, 2020 01:31
Show Gist options
  • Save chadhamre/e33637574566bcfe337cdbfb97dbf8d6 to your computer and use it in GitHub Desktop.
Save chadhamre/e33637574566bcfe337cdbfb97dbf8d6 to your computer and use it in GitHub Desktop.
Fast git branch switcher
#!/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 "$@"
@chadhamre
Copy link
Author

chadhamre commented Apr 20, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment