GitJune 29, 2025

Useful Git Aliases

Defines helpful Git aliases for cleaning up branches, viewing recent branches, interactive rebasing, pretty logging, undoing commits, amending commits, and listing aliases.

Each entry keeps the writeup and source together, so the page reads like a clipped page from the archive rather than a detached utility screen.

Git configLanguage
22Lines
4Tags
3Related

The implementation

The detail page preserves the practical behavior of the original route: the writeup stays readable, the source remains copyable and syntax highlighted, and the item can still link back into the rest of the catalog.

git-aliases.gitconfig
1# Add to ~/.gitconfig
2[alias]
3    # Delete merged branches
4    cleanup = "!git branch --merged | grep -v '\*' | xargs -n 1 git branch -d"
5    
6    # Show branches by last commit date
7    recent = "!git for-each-ref --sort='-committerdate' --format='%(refname:short)' refs/heads | head -20"
8    
9    # Interactive rebase for last n commits
10    fixup = "!f() { git rebase -i HEAD~$1; }; f"
11    
12    # Show a pretty log
13    lg = "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
14    
15    # Undo last commit but keep changes
16    undo = "reset HEAD~1 --soft"
17    
18    # Amend last commit without editing message
19    amend = "commit --amend --no-edit"
20    
21    # List aliases
22    aliases = "config --get-regexp alias"

More from the lab

Related utilities

View full catalog