Skip to content

Instantly share code, notes, and snippets.

@austinhyde

austinhyde/.bashrc

Created Jan 25, 2021
Embed
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 "$@";
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"
}
@austinhyde

This comment has been minimized.

Copy link
Owner Author

@austinhyde austinhyde commented Jan 25, 2021

image

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