Git workflow: add & commit
This course follows a change from the working tree to the commit history in Git. It explains why a commit records the staging area and how to stage whole files, tracked files only, or single hunks with git add -p. It covers commit messages with an imperative subject line and a body that explains why. It then shows how to undo mistakes with git restore, git reset, git commit --amend and git revert. It ends by building a small Rails feature as three clean commits.
What you'll learn
- ✓Why a commit captures the staging area and how to check it with git diff --staged
- ✓Staging with git add ., -A, -u and partial staging with git add -p
- ✓Writing commit messages with an imperative subject, a body and atomic commits
- ✓Undoing changes safely with git restore and the three levels of git reset
- ✓Fixing the last commit with --amend and undoing shared commits with git revert
From working tree to history: the commit lifecycle
The last course introduced three states a file moves through, and let you use git add and git commit just enough to prove a repository worked. This course is the deep dive. It covers every option, every safety net, and the habits that make a commit history readable for a teammate.
Read the full lesson free →Curriculum
7 lessonsFrom working tree to history: the commit lifecycle
A commit captures the staging area, so edits made after git add stay out until staged again.
git add: staging precisely what you want
Compares git add ., -A and -u, and uses git add -p to stage only part of a file.
git commit: anatomy of a good commit
Covers commit message format, multi-line messages, the limit of git commit -a, and atomic commits.
Undoing before you commit: restore and reset
Shows which restore and reset commands keep your changes and which ones discard them for good.
Fixing the last commit: amend
Uses git commit --amend to fix the last message or add a forgotten file before pushing.
Undoing a commit after the fact: reset vs. revert
Contrasts reset, which rewrites history, with revert, which adds a new commit that cancels an old one.
Putting it all together: a clean commit history for a Rails feature
Builds a featured flag for a Rails product as three clean commits, using every tool covered.