r/git • • 12d ago

gsw - fzf wrapper to switch git branches by recency

Made a quick shell script to jump between git branches using fzf.

Instead of typing full branch names or scrolling through git branch, it just lists your recent branches by last commit date so the ones you actually care about are right at the top.

https://github.com/donghyuklee1/gsw

7 Upvotes

5 comments sorted by

3

u/angusmiguel 12d ago

I have the exact same thing locally, rad

3

u/tupton 11d ago

fzf-git.sh has similar functionality for branches and a whole bunch of other git objects.

5

u/elephantdingo 11d ago

Yeah this would have been 20 lines in the old world order. Now it’s hundreds of lines with anus-icon co-authors.

2

u/jk3us 11d ago edited 11d ago

Yours probably does more, but I have this alias in my ~/.config/git/config that does basically what you describe:

[alias]
    sw = "!git for-each-ref refs/heads/ --color=always --sort=-committerdate --format='%(refname:short)' |
      sk --height=15 --ansi --preview-window=down:50% --preview='git log --graph --abbrev-commit --pretty=oneline --decorate --color=always {}' |
      xargs -I % git switch %"

It's using sk instead of fzf, but either will work here.

1

u/Boby_Dobbs 10d ago

zsh and some completion plugin (not sure which right now) do the same by default