Chapter 5. File Management and the Index

When you work in any version control system, you edit in your working directory and commit your changes to your repository for safekeeping. Git also works in this way but inserts an intermediate layer, the index, between the working directory and the repository. The index, also known as the staging directory, is used to stage, or collect, alterations to any files as a final step before the commit.

The index can be regarded as a cache of the current state of your working directory and plays an important role when you are creating a new commit, when you are querying the status of your repository, and when you are performing a merge operation between two branches. (Merges are covered in Chapter 6.) For the purpose of explaining the fundamentals, we will focus on the importance of the index directory in relation to commits, which are covered in Chapter 4.

In this chapter, we will explain how the index or staging directory in Git is unique compared to other version control systems. We will also explain how to manage the index and your collections of files while describing how to add and remove a file from your repository. We will show you how to rename a file in Git and how to catalog the state of the index, before concluding with how to make Git ignore temporary and other irrelevant files that need not be tracked for version control in your repository.

Importance of the Index

When you manage your code with Git, you edit in your working directory, ...

Get Version Control with Git, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.