Git Staging & Commit

Save snapshots of your work.

✍️ 2 exercises in this lesson

Saving changes is a two-step process:

  1. Stage the changes you want: git add file or git add . (everything).
  2. Commit them with a message: git commit -m "Add homepage".

The staging area lets you choose exactly what goes into each commit.

Write clear commit messages in the imperative mood: "Fix login bug", not "fixed stuff".

Key Takeaways: Git Staging & Commit

Mastering Git Staging & Commit helps you write clean and reliable Git code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

Git Staging & Commit Code Example

Git
git add README.md
git commit -m "Add README"

echo "<h1>Home</h1>" > index.html
git add .
git commit -m "Add homepage"
Output
[main (root-commit) 3f2a1b9] Add README
 1 file changed, 1 insertion(+)
[main 8c4d7e2] Add homepage
 1 file changed, 1 insertion(+)
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

Git Staging & Commit Practice Exercises

Check what you learned in “Git Staging & Commit”.

/ 2 solved
Fill in the blank

Stage every change in the folder.

git add 
✓ Correct! Not quite. Try again.
Multiple choice

Which command saves the staged changes as a snapshot?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services