Skip to content

Instantly share code, notes, and snippets.

Created January 25, 2021 22:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Fuzzy Git Checkout - For when you have too many branches
# requires fzf
# co -: check out last branch
# co -anything at all: just does a plain git checkout
# co foo: check out the branch with the closest name to "foo"
function co() {
if [[ $1 == -* ]]; then
git checkout "$@";
git checkout "$(git for-each-ref --format='%(refname:short)' refs/heads/** | fzf -f "$1" | head -1)";
# coi: show a an interactive branch selector with preview of last commit+diff
# coi foo: show the interactive selector with "foo" pre-typed
function coi() {
sel="$(git for-each-ref --format='%(refname:short)' refs/heads/** | fzf --preview 'git show --color {}' -q "$1")" || return $?;
git checkout "$sel"
Copy link


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