Last Updated: October 25, 2017
·
2.715K
· cskeppstedt

Git branch fuzzy search checkout

If you have a ton of ongoing branches, it can be nice to have a fuzzy search to assist you when you are switching branches.

I have extended an example from the phenomenal fzf project that strips the remote/origin part from the branch name, so you may checkout new, local branches.

  • Install fzf (brew install fzf on mac, if you have homebrew)

  • Add this function to your shell, e.g. in .bash_profile:

fbr() {
  git fetch
  local branches branch
  branches=$(git branch -a) &&
  branch=$(echo "$branches" | fzf +s +m -e) &&
  git checkout $(echo "$branch" | sed "s:.* remotes/origin/::" | sed "s:.* ::")
}

You can of course name it anything, I chose fbr for "fuzzy branch".

Demo

Picture