Advanced Aliases
Power User Shortcuts
Advanced Git operations—interactive rebasing, cherry-picking, reflog navigation—demand precision and often involve multi-step workflows. Aliases for these operations serve two purposes: reducing command verbosity and encoding institutional knowledge about flag combinations that work well together.
By this point in your Git journey, you understand the underlying mechanics of history rewriting, commit archaeology, and repository maintenance. These aliases accelerate complex operations you’ve already mastered.
Interactive Rebase Workflow
Interactive rebase involves multiple stages: initiating the rebase, resolving conflicts, continuing after edits, and occasionally aborting when things go wrong. A cohesive set of aliases streamlines this multi-command workflow:
# Start interactive rebase
git config --global alias.rbi 'rebase -i'
# Continue after resolving conflicts or making edits
git config --global alias.rbc 'rebase --continue'
# Abort and return to pre-rebase state
git config --global alias.rba 'rebase --abort'
# Skip problematic commit (use cautiously)
git config --global alias.rbs 'rebase --skip'Practical application:
# Clean up last 5 commits before pushing
git rbi HEAD~5
# Edit TODO list: squash, reword, reorder...
# Conflicts arise during replay
# Resolve conflicts
vim src/conflicted_file.py
git add src/conflicted_file.py
# Continue rebase
git rbc
# If rebase becomes unmanageable
git rba # Returns to original stateWorkflow efficiency: Interactive rebases frequently involve multiple
continue or abort operations. These three-letter aliases (rbi, rbc,
rba) create a memorable pattern that matches the rebase lifecycle: initiate,
continue, abort.
Custom Log Visualization
The standard git log output is verbose and difficult to parse when reviewing
extensive history. This alias creates a compact, visual representation of branch
topology with essential commit information:
git config --global alias.lg "log --graph --pretty=format:'%C(yellow)%h%C(reset) %C(blue)%an%C(reset) %C(cyan)%ar%C(reset) %s %C(auto)%d%C(reset)' --abbrev-commit"Output example:
* a1b2c3d Jane Doe 2 hours ago Add rate limiting (HEAD -> feature/api, origin/feature/api)
* d4e5f6g John Smith 1 day ago Refactor authentication middleware
| * h7i8j9k Jane Doe 3 days ago Implement caching layer (origin/feature/cache)
|/
* k0l1m2n John Smith 1 week ago Initial API framework (main, origin/main)Format breakdown:
%C(yellow)%h%C(reset): Abbreviated commit SHA in yellow%C(blue)%an%C(reset): Author name in blue%C(cyan)%ar%C(reset): Relative commit date in cyan%s: Commit subject line%C(auto)%d%C(reset): Branch/tag references with automatic coloring
Why this matters: The graph visualization (--graph) combined with
color-coded metadata creates a scannable history view. During complex merges or
when reviewing feature branch progress, this compact format reveals branch
topology at a glance without overwhelming terminal output.
Alternative visualization:
# More verbose format with full date and author email
git config --global alias.lga "log --graph --pretty=format:'%C(yellow)%h%C(reset) - %C(cyan)%aD%C(reset) %C(green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an <%ae>%C(reset)' --abbrev-commit"Cherry-Pick Operations
Cherry-picking applies specific commits from one branch to another. Like interactive rebase, it’s a multi-step process that benefits from workflow aliases:
# Cherry-pick with automatic commit
git config --global alias.cp 'cherry-pick'
# Continue after resolving conflicts
git config --global alias.cpc 'cherry-pick --continue'
# Abort cherry-pick operation
git config --global alias.cpa 'cherry-pick --abort'
# Cherry-pick without committing (for modifications)
git config --global alias.cpn 'cherry-pick --no-commit'Practical application:
# Apply hotfix from main to release branch
git sw release/v2.1
git cp a1b2c3d # Cherry-pick hotfix commit
# Conflicts arise
vim src/conflicted_file.py
git add src/conflicted_file.py
git cpc
# Apply commit but modify before committing
git cpn d4e5f6g
vim src/file.py # Make adjustments
git ci -m "Backport feature with modifications for v2.1"Reflog Navigation
The reflog tracks HEAD movement history, enabling recovery of seemingly lost commits. These aliases simplify reflog inspection:
# Concise reflog with relative dates
git config --global alias.hist "reflog --pretty=format:'%C(yellow)%h%C(reset) %C(green)%gd%C(reset) %C(cyan)%ar%C(reset) %s'"
# Show last 20 reflog entries
git config --global alias.recent 'reflog -20'
# Reflog for specific branch
git config --global alias.histbr "reflog show --pretty=format:'%C(yellow)%h%C(reset) %C(green)%gd%C(reset) %C(cyan)%ar%C(reset) %s'"Practical application:
# Accidentally reset branch, need to recover
git hist
# Output:
a1b2c3d HEAD@{0} 5 minutes ago reset: moving to HEAD~3
d4e5f6g HEAD@{1} 10 minutes ago commit: Implement feature
g7h8i9j HEAD@{2} 1 hour ago commit: Add validation
# Recover lost commits
git reset --hard d4e5f6gPro Tip: The reflog is your safety net for history-rewriting operations. The
hist alias makes reflog inspection quick and readable, encouraging regular
checks before destructive operations.
Repository Cleanup
Advanced workflows sometimes require aggressive cleanup operations. These aliases handle common maintenance tasks:
# Remove untracked files and directories
git config --global alias.cleanup 'clean -fd'
# Dry-run to preview what would be deleted
git config --global alias.cleancheck 'clean -fdn'
# Include ignored files in cleanup
git config --global alias.cleanall 'clean -fdx'
# Remove branches that have been merged
git config --global alias.prune-branches "!git branch --merged | grep -v '\\*\\|main\\|develop' | xargs -n 1 git branch -d"Practical application:
# After build, remove generated files
git cleancheck # Preview what will be deleted
git cleanup # Execute cleanup
# After feature merges, remove obsolete branches
git prune-branches
# Deleted branch feature/old-implementation (was a1b2c3d).
# Deleted branch feature/experiment (was d4e5f6g).Warning: git clean permanently deletes files. Always run with -n
(dry-run) first to verify you’re not removing important work. The cleanall
alias (-x flag) removes files listed in .gitignore, which may include local
configuration or credentials—use with extreme caution.
Workflow Automation
Some workflows combine multiple Git operations into cohesive sequences.
Shell-based aliases (prefixed with !) execute arbitrary commands:
# Sync with upstream: fetch, rebase, push
git config --global alias.sync '!git fetch origin && git rebase origin/$(git branch --show-current) && git push'
# Create branch and switch to it
git config --global alias.cob 'checkout -b'
# Commit all changes with message
git config --global alias.ca 'commit -am'
# Push current branch and set upstream
git config --global alias.publish '!git push -u origin $(git branch --show-current)'
# Undo last commit but keep changes staged
git config --global alias.undo 'reset --soft HEAD^'
# Quick commit with WIP message for temporary saves
git config --global alias.wip '!git add -A && git commit -m "WIP: $(date +%Y-%m-%d-%H:%M:%S)"'Practical application:
# Start new feature
git cob feature/new-implementation
# Make experimental changes
vim src/experimental.py
git wip # Commit as work-in-progress with timestamp
# Continue development...
# Ready to push feature
git publish # Creates upstream tracking branch
# Realize last commit should be split
git undo # Keeps changes staged for re-committingComplex workflow example:
# Squash all commits on current branch into one
git config --global alias.squash-all '!git reset --soft $(git merge-base HEAD main) && git commit'This alias finds where your branch diverged from main, resets to that point
(keeping changes staged), then creates a single commit—effectively squashing an
entire feature branch.
Configuration Optimization
Beyond aliases, advanced configurations enhance Git’s behavior for complex workflows:
# Enhanced diff algorithm (better for large refactors)
git config --global diff.algorithm histogram
# Show moved code blocks differently
git config --global diff.colorMoved default
# Include conflict markers showing common ancestor
git config --global merge.conflictstyle zdiff3
# Remember conflict resolutions for reuse
git config --global rerere.enabled true
git config --global rerere.autoupdate true
# Default to rebasing when pulling
git config --global pull.rebase true
# Automatically create remote tracking branches
git config --global push.autoSetupRemote true
# Always push tags with commits
git config --global push.followTags true
# Prune deleted remote branches during fetch
git config --global fetch.prune trueConfiguration synergy: These settings work together to create a workflow
optimized for branch-based development with frequent rebasing. The rerere
(reuse recorded resolution) feature is particularly powerful—if you resolve the
same conflict multiple times (common during interactive rebases), Git
automatically applies your previous resolution.
Consolidated .gitconfig
For reference, here’s a complete advanced .gitconfig section combining all
aliases and configurations:
[alias]
# Interactive rebase workflow
rbi = rebase -i
rbc = rebase --continue
rba = rebase --abort
rbs = rebase --skip
# Log visualization
lg = log --graph --pretty=format:'%C(yellow)%h%C(reset) %C(blue)%an%C(reset) %C(cyan)%ar%C(reset) %s %C(auto)%d%C(reset)' --abbrev-commit
lga = log --graph --pretty=format:'%C(yellow)%h%C(reset) - %C(cyan)%aD%C(reset) %C(green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an <%ae>%C(reset)' --abbrev-commit
# Cherry-pick operations
cp = cherry-pick
cpc = cherry-pick --continue
cpa = cherry-pick --abort
cpn = cherry-pick --no-commit
# Reflog navigation
hist = reflog --pretty=format:'%C(yellow)%h%C(reset) %C(green)%gd%C(reset) %C(cyan)%ar%C(reset) %s'
recent = reflog -20
histbr = reflog show --pretty=format:'%C(yellow)%h%C(reset) %C(green)%gd%C(reset) %C(cyan)%ar%C(reset) %s'
# Cleanup operations
cleanup = clean -fd
cleancheck = clean -fdn
cleanall = clean -fdx
prune-branches = "!git branch --merged | grep -v '\\*\\|main\\|develop' | xargs -n 1 git branch -d"
# Workflow automation
sync = !git fetch origin && git rebase origin/$(git branch --show-current) && git push
cob = checkout -b
ca = commit -am
publish = !git push -u origin $(git branch --show-current)
undo = reset --soft HEAD^
wip = !git add -A && git commit -m "WIP: $(date +%Y-%m-%d-%H:%M:%S)"
squash-all = !git reset --soft $(git merge-base HEAD main) && git commit
[diff]
algorithm = histogram
colorMoved = default
renames = copies
[merge]
conflictstyle = zdiff3
[rerere]
enabled = true
autoupdate = true
[pull]
rebase = true
[push]
autoSetupRemote = true
followTags = true
[fetch]
prune = trueAlias Design Principles
As you develop your own advanced aliases, follow these design principles:
Semantic Naming: Choose names that clearly indicate purpose (
rbcfor “rebase continue” rather than genericc)Workflow Coherence: Group related operations with similar naming patterns (
rbi,rbc,rbaform a coherent rebase trilogy)Safe Defaults: Prefer non-destructive flags; use separate aliases for dangerous operations
Cognitive Load: Don’t create aliases for commands you use infrequently—you’ll forget them and spend time looking them up
Team Alignment: If working on a team, document shared aliases in project README or provide a recommended
.gitconfigtemplateEvolution: Review your aliases quarterly; remove unused ones and refine those that don’t quite fit your workflow
Anti-pattern: Creating dozens of aliases for marginally useful operations. A lean, well-chosen set of 15-20 aliases serves better than an overwhelming collection of 50+ shortcuts you can’t remember.
Summary: Amplifying Advanced Workflows
Advanced aliases accelerate the sophisticated operations you’ve mastered:
- Interactive rebase lifecycle:
rbi,rbc,rba - Visual history inspection:
lg,lga - Commit transplantation:
cp,cpc,cpa - History recovery:
hist,recent - Repository maintenance:
cleanup,prune-branches - Workflow automation:
sync,publish,wip
Combined with optimized configuration settings, these aliases transform Git from a command-line tool into an extension of your development workflow—reducing friction, encoding best practices, and letting you focus on solving problems rather than remembering syntax.
Your Git configuration is a living document. Continuously refine it based on your evolving workflow patterns, and remember: the best alias is one that disappears into muscle memory while solving a real pain point in your daily work.