Progress:
TIER 1 · MODULE 06· Basics

git commit

Write the index into a new commit object on the current branch.

🎯 What & why

Snapshot the current index state into a new commit object on the current branch. The commit captures: the tree, your name/email, a timestamp, parent commit(s), and a message. The branch tip is updated to the new commit.

🧠 Mental model

commit is the orchestrator of three plumbing operations: write-tree (turn the index into a tree object), commit-tree (wrap that tree + metadata into a commit object), and update-ref (move the current branch pointer to the new commit). The previous tip becomes the parent. HEAD follows along because it's a symbolic ref.

🛠️ Synopsis

git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
           [--dry-run] [(-c | -C | --squash | --fixup) <commit>]
           [-F <file> | -m <msg>] [--allow-empty] [--allow-empty-message]
           [--no-verify] [-e] [--author=<author>] [--date=<date>]
           [--cleanup=<mode>] [--[no-]status] [-i | -o]
           [--pathspec-from-file=<file>] [-S[<keyid>]]
           [--] [<pathspec>...]

🎚️ Switches & options

FlagWhat it does
-m "<msg>"Inline commit message. Use -m "summary" -m "body" for multi-paragraph.
-a, --allStage all tracked modifications and deletions before committing. Doesn't pick up new files.
--amendReplace the previous commit (or augment it). Rewrites history — never on shared branches.
-s, --signoffAppend Signed-off-by: Name <email>. Required by some projects (the kernel, etc.).
-v, --verboseShow the full diff in the editor when composing the message. Encourages reading what you're committing.
--no-verifySkip pre-commit and commit-msg hooks. ⚠️ Almost always wrong.
-SGPG/SSH-sign the commit.
--allow-emptyPermit a commit with no changes. Useful for triggering CI.
--fixup=<commit>Create a fixup! commit destined to be squashed into <commit> on a later interactive rebase.

💡 Use cases

🧪 Examples

Standard commit with inline message.
$ git add src/main.c
$ git commit -m 'parse: handle empty header'
Commit message with title and body.
$ git commit -m 'parse: handle empty header' \
               -m 'Previously segfaulted on requests with no headers. Empty header maps to an empty string.'
Amend the previous commit (message + index changes).
$ git add forgotten.c
$ git commit --amend --no-edit
Fixup destined to be auto-squashed via git rebase -i --autosquash.
$ git commit --fixup=<sha> --no-edit

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.