Created
December 22, 2025 17:30
-
-
Save tkalve/755ecedf052a79697ca511a4e3aaf1d3 to your computer and use it in GitHub Desktop.
List recently updated Git branches
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
| <# | |
| .SYNOPSIS | |
| Display recently updated git branches in a formatted table. | |
| .DESCRIPTION | |
| Shows the most recently updated local branches with details including | |
| branch name, last commit date, author and message. | |
| .PARAMETER Count | |
| Number of branches to display. Default is 15. | |
| .EXAMPLE | |
| .\git-recent-branches.ps1 | |
| Shows the 15 most recently updated branches. | |
| .EXAMPLE | |
| .\git-recent-branches.ps1 -Count 5 | |
| Shows the 5 most recently updated branches. | |
| .NOTES | |
| To create a git alias for this script, add the following to your .gitconfig: | |
| [alias] | |
| recent = "!f() { pwsh ~/scripts/git-recent-branches.ps1 \"$@\"; }; f" | |
| Then use it as: | |
| git recent # shows 15 branches (default) | |
| git recent 5 # shows 5 branches | |
| git recent 25 # shows 25 branches | |
| #> | |
| param( | |
| [int]$Count = 15 | |
| ) | |
| git for-each-ref --sort=-committerdate ` | |
| --count=$Count ` | |
| --format='%(refname:short)|%(committerdate:relative)|%(authorname)|%(contents:subject)' ` | |
| refs/heads/ | | |
| ForEach-Object { | |
| $cols = $_ -split '\|',4 | |
| [pscustomobject]@{ | |
| 'Branch name' = $cols[0] | |
| 'Last commit' = $cols[1] | |
| 'Author' = $cols[2] | |
| 'Message' = $cols[3] | |
| } | |
| } | Format-Table -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment