Git Aliases for Branch Listing and Management
Create git aliases to list recent branches, show branch details, and track which branches are merged or unmerged for efficient branch management.
Detailed Explanation
Branch Listing and Management Aliases
As projects grow, you accumulate many branches. These aliases help you stay organized by providing better branch visibility:
[alias]
branches = branch -a
recent = branch --sort=-committerdate --format='%(committerdate:relative) %(refname:short)' -n 10
merged = branch --merged
unmerged = branch --no-merged
What Each Alias Does
branches lists all branches including remote tracking branches. This is useful when you need to see what branches exist on the remote that you might not have locally.
recent is particularly powerful. It sorts branches by the most recent commit date and shows the relative timestamp alongside the branch name. The -n 10 limits output to the 10 most recent:
3 hours ago main
5 hours ago feature/user-auth
2 days ago fix/parser-bug
1 week ago experiment/new-ui
merged and unmerged help with cleanup. After merging feature branches, run git merged to see which branches are safe to delete.
Verbose Branch Info
Add -vv for detailed tracking information:
[alias]
brv = branch -vv
This shows each branch's last commit and its upstream tracking status, revealing which branches are ahead, behind, or have a gone remote.
Remote Branch Tracking
[alias]
track = branch -u
This sets the upstream tracking branch, which is useful when you create a local branch and want to link it to a remote branch.
Use Case
Use these aliases when managing a repository with many active branches, during sprint retrospectives to see which feature branches are still open, or before cleanup operations to identify branches that have been merged and can be safely removed.