Git Aliases That Save Hours Every Week

发布于:2026-03-12 · #git

If you use git daily, you’re probably typing the same 5-10 commands hundreds of times a week. Git aliases fix that.

Setup

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

plaintext
UTF-8|41 Lines|
[alias]
    # Status & info
    s = status -sb
    l = log --oneline -20
    ll = log --oneline --graph --all -30

    # Staging
    a = add
    aa = add -A
    ap = add -p

    # Commits
    c = commit
    cm = commit -m
    ca = commit --amend --no-edit
    cam = commit --amend

    # Branches
    co = checkout
    cb = checkout -b
    bd = branch -d
    bD = branch -D

    # Push & pull
    p = push
    pf = push --force-with-lease
    pl = pull --rebase

    # Diff
    d = diff
    ds = diff --staged
    dn = diff --name-only

    # Stash
    st = stash
    stp = stash pop
    stl = stash list

    # Reset
    unstage = reset HEAD --
    undo = reset --soft HEAD~1

The Ones I Use Most

git s — Compact Status

Bash
UTF-8|4 Lines|
$ git s
## main...origin/main
 M src/components/Header.astro
?? src/content/blog/new-post.md

The -sb flag gives you branch info and short format. No noise, just what changed.

git l — Quick Log

Bash
UTF-8|4 Lines|
$ git l
a1b2c3d Add dark mode toggle
e4f5g6h Fix header alignment
i7j8k9l Update dependencies

Twenty commits, one line each. Enough to orient yourself without scrolling.

git ap — Patch Add

The most underused git command. git add -p lets you stage individual chunks within a file:

Bash
UTF-8|3 Lines|
$ git ap
# Shows each change and asks:
# Stage this hunk [y,n,q,a,d,s,e,?]?

This is how you make clean, focused commits instead of “fixed stuff” commits.

git undo — Soft Reset

Bash
UTF-8|2 Lines|
$ git undo
# Undoes the last commit but keeps all changes staged

Made a typo in the commit message? Forgot to add a file? git undo is your safety net.

git pf — Safe Force Push

Bash
UTF-8|3 Lines|
$ git pf
# push --force-with-lease
# Force pushes BUT fails if someone else pushed first

Never use --force. Always use --force-with-lease. It prevents you from overwriting a teammate’s work.

Shell Aliases (Even Faster)

For commands you run 50+ times a day, add shell aliases too:

Bash
UTF-8|8 Lines|
# ~/.zshrc
alias g="git"
alias gs="git s"
alias gc="git cm"
alias gp="git p"
alias gl="git l"
alias gd="git d"
alias ga="git aa"

Now gs shows status, gc "message" commits, gp pushes. Three characters per command.

The Compound Effect

These aliases save maybe 2-3 seconds per command. But over 100+ git operations per day, that’s 5 minutes. Over a year, that’s 30+ hours — plus the cognitive load reduction of not remembering long flags.


Start with s, l, cm, and undo. Add more as you feel friction. Your future self will thank you.

Default Paper Cactus Velocity Twilight Whono Hexink