Git

Lesson 06

Reviewing diffs before push

Inspect unstaged, staged, and committed changes before pushing so accidental files and debug edits do not leave your machine.

Good Code

pre-push-review.sh
# Check both file content and the commits about to leave the branch.
git diff --check
git diff
git diff --staged
git log --oneline origin/main..HEAD
git push

Bad Code

pre-push-review.sh
# The first real review happens after the push, which is too late.
git add .
git commit -m "final"
git push

Review Notes

What to review

Good Code

The good version checks whitespace issues, reviews both unstaged and staged changes, and confirms which commits are about to be pushed.

Bad Code

The bad version sends the final state upstream without a local review pass.

Takeaways

  • A push should come after a local review pass, not be the first time anyone sees the final diff.