The Git Index

The index is the data structure used as Git's staging area. It records the content that will form the next tree when a commit is created. Commands such as git add update the index.

Understanding the index explains why staging and committing are separate operations.

Inspect the Index
git add src/app.js
git ls-files --stage

git diff
git diff --cached
💡 git ls-files --stage exposes entries in the index. git diff compares the working tree with the index, while git diff --cached compares the index with HEAD.
Key Takeaways
  • The index is Git's staging area.
  • git add updates the index.
  • The next commit is constructed from the staged index state.
Knowledge Check

What does `git add` primarily update?