#TIL: CLI Tricks for Git with FZF

#TIL: CLI Tricks for Git with FZF

Does your current process to checkout a Git branch look something like this?

Git branch checkout
Git Checkout

  • "git branch"?or?"git branch -a"
  • outputs a non-interactive list of branches
  • Double-click an entry
  • do?CTRL-C?or right-click and copy
  • close the list
  • paste the entry to the terminal
  • prepend entry with?git checkout


Going through these many steps decreases productivity and makes working with Git a real struggle. The good news is, there is a way to work around this and make the whole process much leaner!

Using FZF, the seven steps listed above become a one-liner: "git branch -a | fzf | xargs git checkout". This opens up an interactive dropdown that you can now easily navigate with arrows and the search input.

The last step to make this even easier to use would be to create an alias for the command, as follows:

"~/.bashrc

alias gb="git branch -a | fzf | xargs git checkout""


You should now be able to use this with a?"gb"?shorthand, making your experience smoother. Happy coding!

Git filtering


If you are looking for a guide on using Git with visual tools like Fork, check out this blog post by Chris Manson : https://mainmatter.com/blog/2021/05/26/keeping-a-clean-git-history/

要查看或添加评论,请登录

Mainmatter的更多文章

社区洞察

其他会员也浏览了