-
-
Save nielswind/111eba9ed6b10f7be7a9cf84253a1422 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# fast select and change branch in git using fzf | |
set -euo pipefail | |
IFS=$'\n\t' | |
SEARCH="$*" | |
if [[ '-' == "${SEARCH}" ]]; | |
then | |
git checkout - | |
exit $? | |
fi | |
[[ -x `which fzf` ]] || (echo fzf required; exit 1) | |
git root || exit 1 | |
export FZF_DEFAULT_OPTS='--height 40% --border' | |
B=$((git branch -v | grep "^\* "; git branch -v | grep -v "^\* ")| fzf -1 --prompt 'checkout branch: ' -q "${SEARCH}" | tr -s ' '|cut -d" " -f2) | |
[[ ! -e "$B" ]] && git checkout $B |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment