Resourcesโ€บGit Tricksโ€บ15 Git Aliases Every Developer Should Have
๐Ÿ”€Git Tricksโ€” 15 Git Aliases Every Developer Should Haveโฑ 5 min

15 Git Aliases Every Developer Should Have

Stop typing long git commands. These 15 aliases cut your most common git operations down to 2-3 keystrokes.

๐Ÿ“…January 11, 2026โœTechTwitter.iogitaliasesproductivityterminal

Why Git Aliases Matter

git status, git log --oneline --graph --decorate, git checkout -b feature/... โ€” you type these hundreds of times a week. Aliases turn them into muscle memory that takes milliseconds.

Add all of these to your ~/.gitconfig under [alias]:


The Essential Set

[alias]
  # Status shorthand
  st = status -sb

  # Add all and commit in one
  ac = !git add -A && git commit -m

  # Short log with graph
  lg = log --oneline --graph --decorate --all

  # Last commit details
  last = log -1 HEAD --stat

  # Undo last commit (keep changes staged)
  undo = reset --soft HEAD~1

  # Discard all uncommitted changes
  nuke = !git reset --hard && git clean -fd

  # List all branches with last commit date
  branches = branch -v --sort=-committerdate

  # Checkout to previous branch
  back = checkout -

  # Push current branch and set upstream
  pushup = !git push -u origin $(git rev-parse --abbrev-ref HEAD)

  # Pull with rebase (cleaner history)
  pullr = pull --rebase

  # Show what changed in last commit
  show-last = show HEAD --stat

  # Find commits by message
  find = log --all --grep

  # Stash with a message
  save = stash push -m

  # List all stashes
  stashes = stash list

The Most Used Ones Explained

st โ€” Better Status

$ git st
## main...origin/main [ahead 2]
M  src/api.ts
?? src/new-file.ts

-sb gives you the short format with branch info. Much cleaner than the full status output.

lg โ€” Visual Log

$ git lg
* a4ff8b3 (HEAD -> main) fix: rate limiter edge case
* 72e7b6f feat: add user auth
| * 9af12b3 (origin/feature/payments) feat: payment integration
|/
* 3b892c1 chore: initial commit

This is the most useful alias. One command gives you the full repo history with branching visualization.

ac โ€” Add All + Commit

git ac "fix: resolve null pointer in user service"

Equivalent to git add -A && git commit -m "...". Saves the most keystrokes per day.

undo โ€” Soft Undo Last Commit

git undo

Moves HEAD back one commit but keeps your changes staged. Perfect for "I committed too early" situations.

back โ€” Return to Previous Branch

git checkout main
# do something
git back  # returns to whatever branch you were on

Equivalent to cd - in the terminal. Invaluable.

pushup โ€” Push + Set Upstream

git pushup

Pushes the current branch and sets the upstream tracking branch. No more remembering git push -u origin branch-name.


Adding Aliases from the Command Line

You can also add aliases without editing ~/.gitconfig directly:

git config --global alias.st "status -sb"
git config --global alias.lg "log --oneline --graph --decorate --all"
git config --global alias.undo "reset --soft HEAD~1"

Shell Aliases for the git Command Itself

In your .bashrc or .zshrc, also add:

alias g='git'
alias ga='git add'
alias gc='git commit -m'
alias gp='git push'
alias gl='git lg'
alias gs='git st'

Now g st is all it takes.


Key Takeaways

  • Add aliases to ~/.gitconfig under [alias] โ€” they persist across all repos
  • lg (visual log) and ac (add+commit) save the most time
  • undo is safer than reset for fixing commits
  • pushup eliminates the boilerplate of pushing new branches
  • Shell aliases for git itself compound the savings