Staging & Committing
A commit is a saved snapshot of your project. Getting there is a two-step process: you stage the changes you want to save, then you commit them.
Why staging exists
It would be simpler if Git just committed every changed file automatically — but that would force every commit to be "everything I touched today," which is rarely what you actually want. The staging area (sometimes called the "index") is a holding zone in between: you choose exactly which changes go into the next commit, even if you've been editing five different files for five different reasons. This lets you split unrelated changes into separate, focused commits instead of one messy one.
git add
Staging a file is done with git add:
git add index.html
To stage everything that's changed at once, use a dot:
git add .
Run git status afterward and you'll see the file listed under "Changes to be committed" instead of "Untracked files" — it's staged, but not yet part of a permanent snapshot.
git commit
Once something is staged, commit it with a message describing what changed:
git commit -m "Add homepage markup"
[main (root-commit) 4a1f9c2] Add homepage markup 1 file changed, 12 insertions(+) create mode 100644 index.html
That commit is now a permanent point in your project's history — it has a unique ID (4a1f9c2 above), an author, a timestamp, and a message. You can always come back to exactly this state later, even after hundreds more commits.
Writing a good commit message
A commit message is a note to your future self and to anyone else reading the history. "fixed stuff" tells you nothing six months from now; "Fix header overlapping nav on small screens" tells you exactly what problem existed and what changed. A useful convention:
- Keep the first line short (under ~50 characters) and written as an instruction: "Add", "Fix", "Remove", not "Added" or "Fixes".
- If you need more detail, leave a blank line after the summary and write it below —
git commitwith no-mopens your editor for exactly this. - One logical change per commit. If your message needs the word "and" to describe it, consider splitting it into two commits.
.git folder. Sharing commits with other people or a service like GitHub is a separate step, git push, covered in Working with Remotes.