Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Created May 6, 2022 04:03
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 trilliwon/6366cbf32c1edf47df95db608c4fa9f5 to your computer and use it in GitHub Desktop.
Save trilliwon/6366cbf32c1edf47df95db608c4fa9f5 to your computer and use it in GitHub Desktop.
fzf
$ git branch | fzf
$ git switch $(git branch | fzf)
$ git checkout $(git for-each-ref refs/heads/ --format='%(refname:short)' | fzf)

Or add below script to .zshrc

fbr() {
  local branches branch
  branches=$(git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format="%(refname:short)") &&
  branch=$(echo "$branches" |
           fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
  git switch $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}

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