Git workflows¶
Day-to-day Git beyond add/commit/push.
Rewriting the last commit¶
Forgot a file or a typo in the message? Amend instead of stacking a new commit:
git add forgotten_file
git commit --amend --no-edit # keep the message
git commit --amend # edit the message
Fixup commits + autosquash¶
Mark a fix as belonging to an earlier commit, then squash on rebase:
git commit --fixup=<sha>
git rebase -i --autosquash <sha>~1
Interactive rebase to clean history¶
git rebase -i HEAD~5
# reorder, squash, reword before opening a PR
Worktrees for parallel branches¶
Check out a second branch without stashing — a separate working dir sharing
one .git:
git worktree add ../proj-hotfix hotfix/login
git worktree list
git worktree remove ../proj-hotfix
Finding a regression with bisect¶
git bisect start
git bisect bad HEAD
git bisect good v1.4.0
# test, then: git bisect good | git bisect bad ... until found
git bisect reset
See also: Linux CLI recipes for grepping history.