Skip to content

Instantly share code, notes, and snippets.

@qmchenry
Created November 9, 2020 17:42
Show Gist options
  • Save qmchenry/48c036272c0bbdde12bd6c3833b2db5c to your computer and use it in GitHub Desktop.
Save qmchenry/48c036272c0bbdde12bd6c3833b2db5c to your computer and use it in GitHub Desktop.
git interactive branch switcher
#!/bin/bash
select branch in $(git branch | cut -c3-)
do
git switch $branch
exit
done
@qmchenry
Copy link
Author

qmchenry commented Nov 9, 2020

Install by creating a file with the above contents in your path (like /usr/local/bin/git-switcher) and making it executable (chmod +x /usr/local/bin/git-switcher).

Use with git switcher in a directory with a repo. The script will list all existing branches indexed by an integer. Selecting a branch by number will switch to that branch.

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