Git architecture
Git uses a three-tier architecture. The layers are:
- Working tree, i.e., working directory
- Index, i.e., staging area
- Repository
Working tree
The working tree, or working directory, consists of the files you are working on. This is where you perform your day-to-day tasks, and it's the place where you:
- Edit files
- Add new files
- Delete files
In this layer, the files are not yet tracked by Git unless they are added to the index, i.e., the staging area. Changes made here are considered "untracked" until explicitly added to the next layer.
Index
The index, or staging area, is where commits are prepared. Once staged, the files from the working tree are compared to those in the repo. Changes to files in the working tree are marked as modified before committing them.
This layer allows you to:
- Review changes before committing
- Selectively stage parts of files
The staging area ensures that only the changes you want to include are committed.
Repository
The repository, i.e., “repo,” is the final layer where the history of your project is stored and all changes to your project files are tracked. It contains all the commits, branches, tags, and metadata.
This layer provides:
- A complete history of changes
- The ability to collaborate with others
- Version tracking and branching capabilities
When you commit changes, they are moved from the index to the repository. Each commit in the repository represents a snapshot of the project at a given point in time.
To summarize Git's three-tier architecture:
- The working directory is where you make changes.
- The staging area is where you prepare changes for the next commit.
- The repository is where the project's history is stored.
This architecture allows for a flexible and powerful way to manage project versions, collaborate with others, and maintain a robust history of changes.