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 "$@"; | |
else | |
git checkout "$(git for-each-ref --format='%(refname:short)' refs/heads/** | fzf -f "$1" | head -1)"; | |
fi | |
} | |
# 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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.