Image of Austin Gatlin's face
March 15, 2022

Git Working Directory and Index

Short Version

The Working Directory is your current codebase and is where the red changes in git status live. The Index is the pre-commit staging area and is where the yellow changes in git status live.

Longer Version

Working Directory

The working directory is the directory of code you are working on. It is your current codebase, your current directory, your current branch. It is also called the working tree.

As you change the code in your "working directory", git observes those changes and considers them to be in one of four states: Untracked, Unmodified, Modified, Staged.

  • Newly created files are Untracked.
  • Old files you haven't changed are Unmodified.
  • Old files you have changed are Modified.
  • Files you've added to the index, aka the staging area, are considered Staged.


From git add --help:

The "index" holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit.

When you make changes and run git status, you see file paths colored red. Those are referring to the changes in your working directory. Next, you run git add to stage the changes you want to eventually commit. Those staged changes are now in the index. Now, when you run git status, you see the staged changes colored yellow. Finally, you run git commit. That will take the changes in the index and create a snapshot of them, which is added to git's internal key-value store (which is in .git/objects and can be explored further with git cat-file --help).