Created
January 25, 2021 22:23
-
-
Save austinhyde/1350b57c8118646462b843b1dbbec78b to your computer and use it in GitHub Desktop.
Fuzzy Git Checkout - For when you have too many branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" | |
} |
Author
austinhyde
commented
Jan 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment