Git Aliases — Speed Up Your Git Workflow
DodaTech
3 min read
In this tutorial, you'll learn about Git Aliases. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
What You'll Learn
Create Git aliases to speed up your daily workflow — shortcuts for common commands, advanced aliases with arguments, and productivity boosts.
Why It Matters
You type Git commands dozens of times daily. Aliases eliminate repetition and reduce typos. A few good aliases save minutes per day.
Basic Aliases
git config --global alias.st status
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.df diff
git config --global alias.lg log
# Now instead of:
git status
# Type:
git st
Viewing Your Aliases
# List all configured aliases
git config --global --get-regexp alias
# Or edit the config file directly
git config --global --edit
# or ~/.gitconfig
Productivity Aliases
# One-line log with graph
git config --global alias.lg "log --oneline --graph --decorate --all"
# Last commit
git config --global alias.last "log -1 HEAD --stat"
# Show uncommitted changes
git config --global alias.uncommitted "diff --cached"
# List branches with last commit
git config --global alias.branches "branch -a -v"
# Show current branch
git config --global alias.current "rev-parse --abbrev-ref HEAD"
# Pretty log with author and date
git config --global alias.hist "log --pretty=format:'%C(yellow)%h%Creset %C(cyan)%ad%Creset %C(green)%an%Creset %s' --date=short"
# Show file history with blame
git config --global alias.bl "blame -w -C"
# Search commit messages
git config --global alias.find "log --oneline --grep"
# Count commits per author
git config --global alias.count "shortlog -sn"
# Unstage files
git config --global alias.unstage "reset HEAD --"
# Remove untracked files (dry run)
git config --global alias.clean-dry "clean -dn"
# Remove untracked files (force)
git config --global alias.clean-force "clean -fd"
Advanced Aliases with Functions
Some aliases need shell functions (use ! prefix):
# Create a branch and switch to it
git config --global alias.nb "!git checkout -b"
# Delete merged branches (dry run)
git config --global alias.clean-branches \
"!git branch --merged | grep -v '\\*\\|main' | xargs -n 1 echo"
# Delete merged branches (force)
git config --global alias.clean-branches-force \
"!git branch --merged | grep -v '\\*\\|main' | xargs -n 1 git branch -d"
# Search all commits for a string
git config --global alias.search \
"!f() { git log --all --oneline -S \"$1\"; }; f"
# Find a file in history
git config --global alias.find-file \
"!f() { git log --all --oneline --name-only -- \"$1\" | head; }; f"
# Interactive rebase last N commits
git config --global alias.reword \
"!f() { git rebase -i HEAD~$1; }; f"
My Recommended Aliases
Add all of these to ~/.gitconfig:
[alias]
# Status
st = status
s = status -sb
# Log
lg = log --oneline --graph --decorate --all
ll = log --oneline
hist = log --pretty=format:'%C(yellow)%h %C(green)%an %C(cyan)%ar %Creset%s'
last = log -1 HEAD
# Branching
co = checkout
br = branch
nb = !git checkout -b
merged = branch --merged
delete-merged = !git branch --merged | grep -v '\\*\\|main\\|develop' | xargs -n 1 git branch -d
# Committing
ci = commit
ca = commit --amend --no-edit
cia = commit -a --amend --no-edit
# Diffs
df = diff
dc = diff --cached
ds = diff --stat
# Undoing
unstage = reset HEAD --
undo = reset --soft HEAD~1
discard = restore .
discard-all = !git reset --hard HEAD && git clean -fd
# Remote
up = !git pull --rebase && git push
pu = push -u origin HEAD
pr = !gh pr create
# Files
find = !f() { git log --oneline --all -S "$1"; }; f
graph = log --graph --all --oneline --decorate
Sharing Aliases with Your Team
# Install script for team members
cat > .gitaliases << 'EOF'
[alias]
st = status
co = checkout
lg = log --oneline --graph --decorate --all
EOF
# Each team member runs:
git config --local include.path ../.gitaliases
Using External Commands
You can use any external tool:
git config --global alias.vimdiff "difftool --tool=vimdiff"
git config --global alias.vsdiff "difftool --tool=vscode"
# Open GitHub repo in browser
git config --global alias.browse "!open https://github.com/$(gh repo view --json nameWithOwner -q .nameWithOwner)"
Measuring Savings
# Without aliases:
git log --oneline --graph --decorate --all # 47 characters
# With alias:
git lg # 6 characters
# Time saved per day: ~2 minutes
# Time saved per year: ~8 hours
← Previous
Git Ignore — The .gitignore File Explained
Next →
Git Internals — How Git Really Works Under the Hood
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro