Last active
May 28, 2026 14:23
-
-
Save smuuf/fbbaed181e25593532cf57ad1b95b97d to your computer and use it in GitHub Desktop.
git recent-branches alias - list local branches with recent commits
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
| #!/bin/sh | |
| # Install with: | |
| # curl -fsSL https://gist.githubusercontent.com/smuuf/fbbaed181e25593532cf57ad1b95b97d/raw/recent-branches.sh | sh | |
| ALIAS='!r() { | |
| refbranch=${1:-origin/main}; count=${2:-20}; | |
| git for-each-ref --sort=-committerdate refs/heads --count=${count} --color \ | |
| --format="%(refname:short)|%(HEAD)%(color:yellow)%(refname:short)|%(color:bold green)%(committerdate:relative)|%(color:blue)|%(subject)|%(color:magenta)%(authorname)|%(color:reset)" \ | |
| | while IFS="|" read -r branch rest; do | |
| branch=$(echo "$branch" | tr -d "* "); | |
| ahead=$(git rev-list --count "${refbranch}..${branch}" 2>/dev/null || echo "?"); | |
| behind=$(git rev-list --count "${branch}..${refbranch}" 2>/dev/null || echo "?"); | |
| echo "$ahead|$behind|$rest"; | |
| done \ | |
| | column -t -s"|" -R1,2,4 -T6 -N"+,-, branch,lastcommit, ,message,author"; | |
| }; r' | |
| git config --global alias.recent-branches "$ALIAS" | |
| echo "✓ git recent-branches installed" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment