ProgramGuru

Stage changes and create commits

Stage changes and create commits

A good commit should tell a future reader what changed and why that change belongs together. Git lets you prepare exactly that snapshot before recording it.

What you’ll learn

  • Stage selected paths.
  • Create a commit with a useful message.
  • Explain when amending is appropriate.

Prepare one intentional checkpoint

  1. Edit

    Make project changes.

    working tree
  2. Stage

    Choose what belongs together.

    git add
  3. Commit

    Record that selected snapshot.

    new commit
new commit

Commit the staged snapshot, not every current edit

git add copies selected working-tree content into the staging area. git commit records the staged snapshot and advances the current branch.

A concise commit message should describe the intent of the change. Use git commit --amend to replace your most recent local commit when you forgot a file or need to fix its message, but avoid casually rewriting commits other people may already use.

Create your first focused commit

Run this in a disposable practice repository unless the lesson explicitly says otherwise.

git add README.md notes.txt
git commit -m "Add initial notes files"

git status

After the commit, the current branch points to the new commit. If no additional edits remain, git status reports a clean working tree.

Practice: Add and commit

Your task: Make two unrelated edits in two files. Stage only one file and commit it. Confirm the other edit remains in the working tree for a later commit.

Common pitfall to avoid

Do not make huge 'everything changed' commits by habit. Smaller coherent commits are easier to review, revert and understand.

Check your understanding

What does git commit record by default?
Choose one answer. You can try again.

Answer and explanation

The snapshot prepared in the staging area.

Correct.

Add and commit: what to remember

Stage changes and create commits is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.

Read further: official supporting documentation.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Inspect changes with status and diff →