Created
November 21, 2025 15:54
-
-
Save eskil/29cf9783fa8c116bf1f96488f3447376 to your computer and use it in GitHub Desktop.
git recent alias that shows recent branch activity, uses fzf to switch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [alias] | |
| recent = "!f(){ refbranch=${1:-origin/master}; count=${2:-20}; rawlist=$(git for-each-ref --sort=-committerdate --format='%(refname:short)|%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)%(subject)|%(color:magenta)%(authorname)%(color:reset)' --color=always --count=\"$count\" refs/heads | while IFS='|' read -r branch color_branch date msg author; do clean_branch=$(echo \"$branch\" | tr -d '*'); ahead=$(git rev-list --count \"$refbranch..$clean_branch\" 2>/dev/null || echo 0); behind=$(git rev-list --count \"$clean_branch..$refbranch\" 2>/dev/null || echo 0); printf \"%s|%s|%s|%s|%.70s|%s\n\" \"$ahead\" \"$behind\" \"$color_branch\" \"$date\" \"$msg\" \"$author\"; done); displaylist=$( (printf \"%s\n\" \"$rawlist\" | column -ts'|') ); selected=$(printf \"%b\" \"$displaylist\" | fzf --ansi --with-nth=1.. --delimiter='|' --prompt='Recent Branches › ' --reverse --color='pointer:161,marker:168'); [ -z \"$selected\" ] && exit 0; branch=$(printf \"$selected\" | awk '{printf $3}' ); echo \"Switching to $branch\"; git switch \"$branch\"; }; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment