Skip to content

Instantly share code, notes, and snippets.

@nielswind
Last active February 3, 2022 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielswind/111eba9ed6b10f7be7a9cf84253a1422 to your computer and use it in GitHub Desktop.
Save nielswind/111eba9ed6b10f7be7a9cf84253a1422 to your computer and use it in GitHub Desktop.
#!/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