Git aliases transform repetitive, long commands into simple shortcuts. Whether you're tired of typing git status
hundreds of times a day or want to automate complex workflows, aliases are your path to Git mastery and increased productivity.
Understanding Git Aliases
Git aliases are custom shortcuts for Git commands. They can range from simple abbreviations to complex scripts that automate entire workflows.
Creating Your First Alias
# Simple alias for status
git config --global alias.st status
# Now you can use
git st
# Instead of
git status
Essential Git Aliases
Basic Command Shortcuts
# Status, add, commit, and more
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.cm commit
git config --global alias.df diff
git config --global alias.lg "log --oneline"
# Usage
git st # git status
git co main # git checkout main
git br -a # git branch -a
git cm -m "message" # git commit -m "message"
Enhanced Log Viewing
# Beautiful log output
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
# Compact log
git config --global alias.ll "log --oneline --decorate"
# Log with stats
git config --global alias.ls "log --stat"
# Log with patches
git config --global alias.lp "log -p"
# Today's commits
git config --global alias.today "log --since='00:00:00' --oneline --author='$(git config user.name)'"
Quick Operations
# Stage all changes
git config --global alias.aa "add -A"
# Commit with message
git config --global alias.cm "commit -m"
# Amend last commit
git config --global alias.amend "commit --amend --no-edit"
# Undo last commit (keep changes)
git config --global alias.undo "reset HEAD~1 --soft"
# Discard last commit (lose changes)
git config --global alias.nuke "reset HEAD~1 --hard"
Advanced Aliases
Complex Workflows
# Quick save work in progress
git config --global alias.wip "!git add -A && git commit -m 'WIP'"
# Undo WIP commit
git config --global alias.unwip "!git log -n 1 --oneline | grep -q 'WIP' && git reset HEAD~1"
# Create feature branch
git config --global alias.feature "!f() { git checkout -b feature/\$1 ${2:-main}; }; f"
# Create bugfix branch
git config --global alias.bugfix "!f() { git checkout -b bugfix/\$1 ${2:-main}; }; f"
Interactive Operations
# Interactive rebase
git config --global alias.ri "rebase -i"
# Interactive add
git config --global alias.ai "add -i"
# Interactive stash
git config --global alias.stash-all "stash save --include-untracked"
Branch Management
# List branches sorted by most recent commit
git config --global alias.recent "!git for-each-ref --sort=-committerdate refs/heads/ --format='%(committerdate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))'"
# Delete merged branches
git config --global alias.cleanup "!git branch --merged | grep -v '\\*\\|main\\|master\\|develop' | xargs -n 1 git branch -d"
# Show current branch
git config --global alias.current "rev-parse --abbrev-ref HEAD"
# Switch to previous branch
git config --global alias.prev "checkout -"
Power User Aliases
Git Flow Shortcuts
# Start feature
git config --global alias.fs "!f() { git flow feature start \$1; }; f"
# Finish feature
git config --global alias.ff "!f() { git flow feature finish \$1; }; f"
# Start hotfix
git config --global alias.hfs "!f() { git flow hotfix start \$1; }; f"
# Finish hotfix
git config --global alias.hff "!f() { git flow hotfix finish \$1; }; f"
Search and Find
# Find branches containing commit
git config --global alias.contains "!f() { git branch -a --contains \$1; }; f"
# Search commit messages
git config --global alias.search "!f() { git log --all --grep=\"\$1\"; }; f"
# Find deleted file
git config --global alias.find-deleted "!f() { git log --all --full-history -- \$1; }; f"
# Show file at specific commit
git config --global alias.show-file "!f() { git show \$1:\$2; }; f"
Statistics and Analytics
# Contribution stats
git config --global alias.stats "shortlog -sn"
# File change frequency
git config --global alias.churn "!git log --all -M -C --name-only --format='format:' | sort | grep -v '^$' | uniq -c | sort -n"
# Today's work
git config --global alias.standup "!git log --since='yesterday' --author='$(git config user.name)' --oneline"
# Lines of code by author
git config --global alias.lines "!git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr"
Shell Function Aliases
Complex Logic with Shell Functions
# Commit with ticket number
git config --global alias.cmt '!f() {
BRANCH=$(git symbolic-ref --short HEAD)
TICKET=$(echo $BRANCH | grep -oE "[A-Z]+-[0-9]+")
if [ -z "$TICKET" ]; then
git commit -m "$1"
else
git commit -m "[$TICKET] $1"
fi
}; f'
# Pull request creation
git config --global alias.pr '!f() {
BRANCH=$(git symbolic-ref --short HEAD)
git push -u origin $BRANCH
hub pull-request -m "$1"
}; f'
Automated Workflows
# Complete feature workflow
git config --global alias.done '!f() {
git add -A
git commit -m "$1"
git push
git checkout main
git pull
git branch -d @{-1}
}; f'
# Sync with upstream
git config --global alias.sync '!f() {
git fetch upstream
git checkout main
git merge upstream/main
git push origin main
}; f'
Platform-Specific Aliases
GitHub Integration
# Open repo in browser
git config --global alias.open '!f() {
URL=$(git remote get-url origin | sed "s/git@github.com:/https:\/\/github.com\//" | sed "s/.git$//")
open $URL
}; f'
# Create pull request
git config --global alias.pull-request '!f() {
BRANCH=$(git symbolic-ref --short HEAD)
git push -u origin $BRANCH
URL=$(git remote get-url origin | sed "s/git@github.com:/https:\/\/github.com\//" | sed "s/.git$//")
open "$URL/compare/$BRANCH?expand=1"
}; f'
GitLab Integration
# Open merge request
git config --global alias.mr '!f() {
BRANCH=$(git symbolic-ref --short HEAD)
git push -u origin $BRANCH
URL=$(git remote get-url origin | sed "s/git@gitlab.com:/https:\/\/gitlab.com\//" | sed "s/.git$//")
open "$URL/-/merge_requests/new?merge_request[source_branch]=$BRANCH"
}; f'
Alias Organization
Categorized Aliases
# Viewing (v*)
git config --global alias.vl "log --oneline"
git config --global alias.vd "diff"
git config --global alias.vs "status -s"
git config --global alias.vb "branch -vv"
# Editing (e*)
git config --global alias.ea "add -A"
git config --global alias.ec "commit"
git config --global alias.em "commit --amend"
git config --global alias.er "reset"
# Workflow (w*)
git config --global alias.wf "!git add -A && git commit -m"
git config --global alias.wp "!git push"
git config --global alias.wu "!git pull"
Project-Specific Aliases
# In project/.git/config
[alias]
deploy = !./scripts/deploy.sh
test = !npm test
build = !npm run build
release = !f() { git tag -a v$1 -m "Release version $1" && git push origin v$1; }; f
Alias Management
Listing All Aliases
# Create alias to list all aliases
git config --global alias.aliases "config --get-regexp '^alias\.'"
# Usage
git aliases
Backup and Share
# Export aliases to file
git config --global --get-regexp '^alias\.' > ~/.git-aliases
# Import aliases
cat ~/.git-aliases | while read line; do
git config --global $line
done
Alias Documentation
# Add help alias
git config --global alias.help-aliases '!f() {
echo "Git Aliases:"
echo " st - status"
echo " co - checkout"
echo " br - branch"
echo " cm - commit -m"
echo " aa - add all"
echo " lg - pretty log"
echo " undo - undo last commit"
echo " wip - save work in progress"
echo " cleanup- delete merged branches"
}; f'
Productivity Boosters
Time-Saving Combinations
# Quick commit and push
git config --global alias.cap '!f() { git add -A && git commit -m "$1" && git push; }; f'
# Fetch, pull, and clean
git config --global alias.refresh '!f() { git fetch --all --prune && git pull && git cleanup; }; f'
# Complete PR workflow
git config --global alias.pr-complete '!f() {
BRANCH=$(git symbolic-ref --short HEAD)
git push -u origin $BRANCH
echo "PR pushed. Waiting for merge..."
read -p "Press enter after PR is merged..."
git checkout main
git pull
git branch -d $BRANCH
git remote prune origin
}; f'
Development Shortcuts
# Start day
git config --global alias.start '!f() {
git checkout main
git pull
echo "Your branches:"
git branch
echo "Recent commits:"
git log --oneline -5
}; f'
# End day
git config --global alias.eod '!f() {
echo "Today'"'"'s work:"
git standup
echo ""
echo "Uncommitted changes:"
git status -s
}; f'
Troubleshooting Aliases
Debugging Complex Aliases
# Add debug alias
git config --global alias.debug '!f() {
set -x
$@
set +x
}; f'
# Debug another alias
git debug lg
Common Issues
# Escaping quotes in aliases
git config --global alias.complex '!f() { echo "It'"'"'s complex"; }; f'
# Using git commands in aliases
git config --global alias.recursive '!git status && git log -1'
# Handling arguments
git config --global alias.args '!f() { echo "First: $1, Second: $2"; }; f'
Team Aliases
Shared Team Configuration
# team-aliases.sh
#!/bin/bash
# Team standard aliases
git config --global alias.feat "checkout -b feature/"
git config --global alias.fix "checkout -b bugfix/"
git config --global alias.push-upstream "push -u origin HEAD"
git config --global alias.sync-main "!git checkout main && git pull && git checkout -"
echo "Team aliases configured!"
Conclusion
Git aliases are more than just shortcuts—they're a way to customize Git to match your workflow perfectly. Start with simple abbreviations, then gradually build more complex aliases as you identify repetitive patterns in your work.
The key is to create aliases that feel natural to you. Whether you prefer short cryptic commands or longer descriptive ones, the goal is to reduce friction and increase your productivity.
Remember: the best alias is the one you'll actually use. Start small, iterate often, and soon you'll have a personalized Git environment that makes you faster and more efficient than ever before.
Share this article
David Childs
Consulting Systems Engineer with over 10 years of experience building scalable infrastructure and helping organizations optimize their technology stack.