Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 19Quick Reference Cheatsheet

Chapter 16 of 19

16. Power Commands & Aliases

Useful one-liners

# Pretty log graph
git log --oneline --graph --all --decorate

# Find what you typed (all history)
git log --all --full-history -- "**/lost-file.txt"

# Search commit messages
git log --grep="payment" --oneline

# See all changes to a function
git log -L :function_name:file.py

# Compare two branches
git diff main..feature/login

# List files changed in last commit
git show --name-only HEAD

# Count commits per author
git shortlog -sn

# Remove file from staging but keep on disk
git rm --cached sensitive.env

# Temporarily switch to another branch without losing work
git switch -c temp-branch   # or git stash

# Clean untracked files (preview first)
git clean -n       # dry run
git clean -fd      # delete untracked files and directories (PERMANENT)

# Set upstream and push in one command
git push -u origin $(git branch --show-current)

Aliases (add to ~/.gitconfig)

[alias]
    s     = status
    st    = status -sb
    co    = switch
    cb    = switch -c
    lg    = log --oneline --graph --all --decorate
    undo  = reset HEAD~1
    unstage = restore --staged
    aliases = config --get-regexp alias
    pushup = push -u origin HEAD
    wip    = commit -am "WIP: checkpoint"
    unwip  = reset HEAD~1

Usage: git lg, git undo, git pushup