Git¶
Beyond add, commit, push. The commands that save you when things go sideways.
Interactive Rebase¶
Rewrite the last 5 commits (reorder, squash, edit messages):
Warning
Never rebase commits that have been pushed to a shared branch.
Bisect¶
Find the commit that introduced a bug using binary search:
git bisect start
git bisect bad # current commit is broken
git bisect good v1.2.0 # this tag was working
# Git checks out a middle commit — test it, then:
git bisect good # or: git bisect bad
# Repeat until Git identifies the first bad commit
git bisect reset # return to original HEAD
Worktrees¶
Work on multiple branches simultaneously without stashing:
List active worktrees:
Remove when done:
Reflog — Undo Almost Anything¶
See every HEAD movement (even after reset):
Recover a commit you accidentally reset away:
Stash¶
Stash with a descriptive name:
List stashes:
Apply a specific stash without removing it:
GitHub CLI (gh)¶
Create a PR from the current branch:
Check out a PR locally by number:
View CI status for the current branch:
Browse the repo in your browser:
Search issues:
Install:
brew install gh·winget install GitHub.cli
Useful Aliases¶
Add to ~/.gitconfig under [alias]:
[alias]
lg = log --oneline --graph --all --decorate
co = checkout
br = branch -vv
st = status -sb
undo = reset --soft HEAD~1
amend = commit --amend --no-edit
wip = !git add -A && git commit -m "WIP"
Log Tricks¶
Commits by a specific author in the last week:
Show files changed in each commit:
Search commit messages: