TetSharing
Git & CLI tutorial · 12 chapters
  1. Terminal basics
  2. Working with files
  3. Pipes and redirection
  4. What Git is
  5. Staging and commits
  6. Viewing history
  7. Comparing changes
  8. Branches
  9. Merging
  10. Merge conflicts
  11. Undoing changes
  12. Remotes, push and pull

Final Git & CLI quiz
Cheat sheet: git commands
Cheat sheet: linux shell commands

Chapter 5 of 12 · By Ethan Cole · Updated November 21, 2026

Git add and git commit: The Staging Area Explained

A commit is a saved snapshot of your project at one moment, together with a message, an author and a date. Commits are the units of history: you can compare them, go back to them and share them.

Three places for your files

Git thinks about files in three areas:

  1. The working directory: the files you see and edit.
  2. The staging area (also called the index): the set of changes you have chosen for the next commit.
  3. The repository: the commits stored in .git.

The middle step is what makes Git different from a simple "save" button. You can edit five files and commit only the two that belong together, keeping each commit focused on one change.

git add

git add file.txt copies the current state of file.txt into the staging area. git add . stages every change in the current folder and below. If you edit a file again after adding it, the new edit is not staged until you add it again; git status will show the file as both staged and modified.

git commit

git commit -m "Add contact page" records everything in the staging area as a new commit. Git prints the branch, a short version of the commit's unique ID (a hash), the message and a summary of what changed. Without -m, Git opens a text editor for a longer message.

Terminal · bash + git · copy and run locally
git init -q
echo "# Recipes" > README.md
echo "Pancakes: flour, milk, eggs" > pancakes.txt
git status --short
git add README.md
git status --short
git commit -m "Add README"
git add pancakes.txt
git commit -m "Add pancake recipe"
echo "Pinch of salt" >> pancakes.txt
git status --short
git commit -am "Add salt to pancakes"
git status --short

Transcript (verified by our test suite in a fresh temp folder)

$ git init -q
$ echo "# Recipes" > README.md
$ echo "Pancakes: flour, milk, eggs" > pancakes.txt
$ git status --short
?? README.md
?? pancakes.txt
$ git add README.md
$ git status --short
A  README.md
?? pancakes.txt
$ git commit -m "Add README"
[main (root-commit) d4dc383] Add README
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
$ git add pancakes.txt
$ git commit -m "Add pancake recipe"
[main 569e6f0] Add pancake recipe
 1 file changed, 1 insertion(+)
 create mode 100644 pancakes.txt
$ echo "Pinch of salt" >> pancakes.txt
$ git status --short
 M pancakes.txt
$ git commit -am "Add salt to pancakes"
[main 431fb9f] Add salt to pancakes
 1 file changed, 1 insertion(+)
$ git status --short

In the transcript, git status --short shows a compact two-column view: ?? means untracked, A in the first column means staged as new, and M in the second column means modified but not staged. Watch how one git add moves a file from the second state to the first.

The hashes in our transcripts are produced by the test run. Yours will be different because they depend on your name, email and the exact time.

Writing good messages

A commit message is a note to your future self and your teammates. Good messages:

  • Start with a short summary in the imperative mood, under about 50 characters: "Fix login redirect", not "fixed stuff".
  • Describe why in an optional body after a blank line, when the reason is not obvious from the change.
  • Cover one logical change per commit, which is what the staging area makes possible.

Shortcut

git commit -am "message" stages every change to files Git already tracks and commits in one step. It skips new, untracked files, which still need git add.

Summary

  • Working directory, staging area, repository: changes move left to right.
  • git add stages, git commit -m records a snapshot.
  • Keep commits focused and messages short and specific.

Quiz: Staging and commits

1. What does the staging area hold?

git add places changes in the staging area; git commit records them.

2. You edit app.js after running git add app.js. What happens to the second edit?

Staging copies the file as it was at that moment.

3. Which command does NOT include brand-new untracked files?

-a only stages files Git already tracks.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.