You've staged changes with git add. The next step is git commit — this permanently saves a snapshot in your repository's history.
The Basic Commit
git commit -m "Add homepage with basic styling"
The -m flag followed by a quoted string is your commit message. It should describe what changed and why, in present tense:
- Good:
"Add contact form to about page" - Good:
"Fix broken link in footer" - Bad:
"stuff"or"asdfasdf"or"fixed things"
Future you (and your teammates) will read these messages when hunting down bugs. Write them for humans, not robots.
What Happens When You Commit
- Git takes everything in the staging area.
- It stores a snapshot with a unique ID (a hash like
a3f9c2b). - It records your name, email, timestamp, and message.
- It clears the staging area for that commit's files (they're now "committed").
After committing, git status should show a clean working tree — unless you have other unstaged changes.
Commit Without -m (Optional)
If you run git commit with no message flag, Git opens your default text editor for you to write a longer message. The first line is the short summary; blank lines and paragraphs below can add detail.
For daily work, -m is faster. Use the editor when a change needs more explanation.
Nothing to Commit?
If you forget to git add first:
git commit -m "Update styles"
# nothing to commit, working tree clean
Git only commits what's staged. Run git status, stage your files, then commit again.
Amending the Last Commit
Made a typo in the message, or forgot to stage a file? If you haven't pushed yet (we'll cover pushing soon), you can fix the most recent commit:
# Forgot to stage a file
git add forgotten-file.css
git commit --amend -m "Add homepage with basic styling"
--amend replaces the last commit with a new one that includes the staged changes and/or a new message. Use this sparingly and only on commits you haven't shared with others yet.
Good Commit Habits
Commit often, commit small. One logical change per commit. A typo fix is one commit; adding a new page is another. Don't bundle unrelated changes.
Check before you commit:
git status
git diff --staged # see exactly what you're about to save
git diff --staged shows the line-by-line differences between your staged files and the last commit. It's your last chance to catch mistakes.
Full Workflow Recap
# Edit files in VS Code, then:
git status
git add index.html styles.css
git status
git diff --staged
git commit -m "Add styled homepage"
git log --oneline
That loop — edit, status, add, commit — is the heartbeat of Git. Next we'll explore git log and reading your project's history.