Skip to content

The Staging Area (Git Index)

After creating a Git repository, you can modify several files in the project’s working tree.

However, you may not want every modification to become part of the next commit.

Git provides an intermediate preparation area called the Staging Area.

The Staging Area is the preparation list for the next commit. It lets you choose which working-tree changes should be included.

The Staging Area is also called the Git Index.

These two terms refer to the same concept:

Staging Area = Git Index

It represents the state that Git is preparing to use for the next commit.

Imagine that you modified three files:

auth.js
feature.js
README.md

The three modifications currently exist in the Working Tree.

However, suppose only the change in auth.js is complete and ready to be recorded. The changes in feature.js and README.md are still unfinished.

The Staging Area allows you to select auth.js without including the other two files.

To place the current content of auth.js in the Staging Area, run:

Terminal window
git add auth.js

The state now looks like this:

Working Tree

  • auth.jsmodified
  • feature.jsmodified
  • README.mdmodified

All three files are modified on disk.

Staging Area (Git Index)

  • auth.jsstaged

Only the content of auth.js is prepared for the next commit. feature.js and README.md stay unstaged.

Only auth.js has been prepared for the next commit.

The modifications in feature.js and README.md still exist on disk in the Working Tree, but they are not part of the prepared snapshot.

git add auth.js does not merely mark the file name.

It places the current content of auth.js into the Git Index as the version prepared for the next commit.

If you later modify auth.js again, the new modification is not automatically added to the existing staged version. You would need to stage the file again if you wanted the newer content included.

When a commit is created, Git records the state prepared in the Staging Area.

In this example:

Staged:
auth.js
Not staged:
feature.js
README.md

Therefore, the next commit includes the staged version of auth.js.

The unstaged modifications in feature.js and README.md remain in the Working Tree and are not included.

Think of the Staging Area as a shopping cart for the next snapshot.

The store contains many available items, but only the items you deliberately place in the cart will be included when you check out.

In the same way:

Working Tree → All current modifications
Staging Area → Changes selected for the next commit
Commit → Records the prepared selection

In our example:

Shopping cart:
✓ auth.js
Still outside the cart:
- feature.js
- README.md

The Staging Area gives you control over what belongs together in the next recorded checkpoint.

Every normal Git project has three important areas.

Understanding these areas makes the Git workflow easier to follow:

Working Tree

Edit project files.

Edit and save

Staging Area

Select what belongs in the next commit.

git add

Repository

Store recorded snapshots.

git commit

Each area has a different responsibility.

The Working Tree, also called the Working Directory, contains the visible project files you open and edit.

It is your daily workspace.

When you edit and save a file, the new content exists in the Working Tree. Saving the file does not automatically prepare it for a commit or add it to Git history.

Working Tree
Purpose: Edit project files
Action: Edit and save

The Staging Area, also called the Git Index, is the preparation area for the next commit.

You use git add to select the current content that should be included.

Staging Area
Purpose: Select what belongs in the next commit
Action: git add

You do not have to stage every modified file.

For example, if you modified:

auth.js
feature.js
README.md

but only auth.js is ready, you can stage only that file:

Terminal window
git add auth.js

The other modifications remain in the Working Tree and do not become part of the next commit.

The Repository contains the project’s recorded history inside .git.

When you create a commit, Git records a new snapshot based on the state currently prepared in the Staging Area.

Repository
Purpose: Store recorded snapshots
Action: git commit

Let us follow auth.js through the three areas of Git. The file does not physically move between folders. Instead, Git keeps track of its state in each area.

  1. Moment 1

    Create the file

    Working Tree: auth.js exists as an untracked file.

    Staging Area: empty.

    Repository: no snapshot of the file exists yet.

  2. Moment 2

    git add auth.js

    Working Tree: still contains auth.js.

    Staging Area: contains the current version of auth.js.

    Repository: still has no snapshot of the file.

  3. Moment 3

    git commit -m “fix login”

    Working Tree: matches the committed version.

    Staging Area: no pending staged changes.

    Repository: contains the new snapshot.

  4. Moment 4 Now

    Edit the file again

    Working Tree: contains new modified content.

    Staging Area: does not contain the new modification.

    Repository: still contains the version saved by the last commit.

We create and save auth.js in the project directory.

  • Working Tree: auth.js exists as an untracked file.
  • Staging Area: Empty.
  • Repository: No snapshot of the file exists yet.

At this moment, the file exists only in the Working Tree. Git can see it, but it has not been selected for the next commit.

Terminal window
git add auth.js
  • Working Tree: Contains auth.js.
  • Staging Area: Contains the current version of auth.js.
  • Repository: Still has no snapshot of the file.

git add copies the current state of auth.js into the Staging Area, preparing that exact version for the next commit.

Terminal window
git commit -m "fix login"
  • Working Tree: Matches the committed version.
  • Staging Area: No pending staged changes.
  • Repository: Contains the new snapshot.

git commit saves the version prepared in the Staging Area as a permanent snapshot in the repository history.

We make another change to auth.js and save it.

  • Working Tree: Contains new modified content.
  • Staging Area: Does not contain the new modification.
  • Repository: Still contains the version saved by the last commit.

The new edit is not automatically staged. To include it in another commit, we must run git add auth.js again before creating the next commit.

The important idea: git add stages the file’s current version at that moment. If you edit the file afterward, the new changes remain in the Working Tree until you stage them again.

The normal movement is:

1. Edit or save files
Working Tree
2. Select the required content
Working Tree → git add → Staging Area
3. Record the prepared state
Staging Area → git commit → Repository

This separation gives you control over the contents of each commit.

Suppose you are working on two different tasks:

  • Fixing the login form.
  • Updating the README documentation.

Both changes may exist in the Working Tree, but you may want to record the login fix first.

You can prepare only the login-related file for the next commit. The README modification remains safely in the Working Tree for later.

Conceptually:

Working Tree:
- auth.js modified
- README.md modified
Staging Area:
- auth.js selected
Next commit:
- Includes the staged state of auth.js
- Does not include the unstaged README.md modification

This allows one commit to represent one focused piece of work.

The three Git areas work together:

  • Working Tree: where you edit and save visible project files.
  • Staging Area: where you select the content for the next commit.
  • Repository: where commits record the prepared snapshots in Git history.

The workflow is:

Edit → Stage the required changes → Commit the staged state

You decide which modifications enter the Staging Area. Therefore, a commit can contain only the files relevant to one task while other unfinished modifications remain in the Working Tree.