git add stages changes — it chooses what goes into the next snapshot. git commit saves those staged changes as a permanent snapshot with a message.Guide
How you actually save work in Git: stage your changes with add, then snapshot them with commit.
This is the one idea that makes Git click. A changed file moves through three areas:
Why the middle step? Because it lets you commit related changes together with a clear message, even if you edited ten files. You choose what goes in.
Plain-English version: git add = "include this in my next save." git commit = "save it, with a note about what I did."
add
After editing files, git add moves them to the staging area. Use a filename for
one file, or . (a dot) to stage everything you've changed.
Stage your changes
$ git add index.html
$ git add . # stage everything changed commitA commit bundles everything in the staging area into one snapshot, with a message. Keep the message short and in the present tense — describe what the change does.
Commit the staged changes
$ git commit -m "Add contact form to homepage" Ctrl+Enter)The -m flag is the message. Without it, Git opens a text editor and asks for one.
Once you're comfortable, git commit -am stages and commits all already-tracked
files in one step (it won't pick up brand-new files — those still need git add).
Stage tracked changes and commit at once
$ git commit -am "Fix typo in footer" git status lists which files are changed or staged. git diff shows
the exact lines that changed, so you can review before committing.
Review before you commit
$ git status
$ git diff
For a bigger change, write a short subject line, then a blank line, then a paragraph of detail.
Run git commit with no -m and Git opens your editor for the full message.
Typo in the message, or forgot to include a file? Repair the most recent commit with
git commit --amend — as long as you haven't pushed it yet.
Amend the last commit
$ git commit --amend -m "Clearer message"
$ # or stage a forgotten file first, then keep the message:
$ git add forgotten.css
$ git commit --amend --no-edit Only amend commits you haven't pushed yet — it rewrites history. The Undo chapter has the full toolkit.
To browse what you've saved, Viewing History covers
git log, git show and git diff; to undo a commit, see
Undo Commits.
Up next: before the history piles up — which files should never be committed, and how to make Git look away.
FAQ
git add stages changes — it chooses what goes into the next snapshot. git commit saves those staged changes as a permanent snapshot with a message.git push is the separate step that sends them up to GitHub.git commit --amend fixes the most recent one, git reset un-commits while keeping your work, and git revert safely undoes a commit you've already pushed. See the Undo Commits chapter.