Why Git Aliases?
If you use Git daily, aliases can save you thousands of keystrokes and make complex commands easy to remember.
Essential Aliases
Add these to your
~/.gitconfig:
``
ini
[alias]
# Status and logs
s = status -sb
lg = log --oneline --graph --decorate
last = log -1 HEAD --stat
# Branching
co = checkout
cob = checkout -b
br = branch
brd = branch -d
# Commits
c = commit
cm = commit -m
ca = commit --amend
# Push/Pull
p = push
pf = push --force-with-lease
pl = pull --rebase
# Stash
st = stash
stp = stash pop
stl = stash list
# Reset
unstage = reset HEAD --
undo = reset --soft HEAD~1
# Diff
d = diff
ds = diff --staged
# Cleanup
cleanup = !git branch --merged | grep -v main | xargs git branch -d
`
Power User Aliases
`
ini
[alias]
# Interactive rebase on last n commits
ri = "!f() { git rebase -i HEAD~$1; }; f"
# Find commits by message
find = log --all --grep
# Show contributors
contributors = shortlog -sn
# Undo last commit but keep changes
uncommit = reset --soft HEAD~1
# Show what I did today
today = log --since=midnight --author='Your Name' --oneline
`
Shell Aliases
Add to your .zshrc
or .bashrc
:
`
bash
alias g='git'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git pull'
alias gd='git diff'
alias gco='git checkout'
alias gb='git branch'
``
Conclusion
Start with a few aliases and add more as you discover repetitive patterns in your workflow. Your future self will thank you!