A Git repository contains your project files along with a special .git directory. The .git directory stores the information Git needs to manage versions, commits, branches, references and other repository data.
.git directory is the heart of
a Git repository. You normally should not manually modify its internal
files.
Git repository structure describes the files and directories used by Git to manage a project.
A typical project contains your source files and a hidden .git directory.
my-project/
│
├── .git/
├── index.html
├── style.css
└── script.js
Here, .git contains Git's internal repository data, while the other files are project files.
The .git directory is created when you run:
git init
It stores the information required by Git to manage the repository.
Without the .git directory, the project directory does not contain the local Git repository metadata.
Git uses this directory to maintain information about the repository and its history.
The working directory is the area where you work with your project files.
For example:
index.html
style.css
script.js
You create and modify files in the working directory.
The staging area contains changes that you have selected for the next commit.
You add files to the staging area using:
git add index.html
The Git repository stores committed project history.
When you create a commit, Git records the staged changes in the repository.
git commit -m "Initial commit"
Working Directory
↓
Staging Area
↓
Git Repository
Changes normally move through these areas as you work with Git.
my-project/
├── index.html
├── style.css
└── script.js
When you edit these files, the changes first exist in your working directory.
Use git add to move changes into the staging area.
git add index.html
You can then check the state with:
git status
After staging changes, create a commit:
git commit -m "Update website"
The commit becomes part of the repository history.
HEAD is a special reference that normally points to the currently checked-out branch.
It helps Git identify the current position in the project history.
Git stores references to branches in the repository. For example, a branch such as main points to a commit in the project history.
main → latest commit
Git internally stores different types of objects to represent repository data.
Common Git object types include:
A blob object stores file content.
The filename itself is not stored inside the blob. Git uses other repository structures to associate content with filenames.
A tree object represents directory information. It connects filenames with the objects representing their contents.
A commit object represents a recorded point in the project's history.
A commit contains information such as the author, commit message and references to the project state.
A Git tag can be used to give a meaningful name to a specific point in repository history.
Tags are often used to identify releases or important versions.
Inside the .git directory, the objects directory stores Git objects.
These objects form an important part of Git's internal data model.
The refs directory contains references used by Git, including references associated with branches and tags.
These references help Git identify important points in repository history.
The HEAD file is located inside the .git directory.
It identifies the current branch or commit reference used by the working tree.
The config file inside .git contains repository-specific configuration information.
For example, repository-specific settings and remote information can be stored here.
The index file is associated with Git's staging area.
When you use git add, Git updates the index to record
what is prepared for the next commit.
.git/
├── HEAD
├── config
├── index
├── objects/
├── refs/
└── ...
The exact contents can vary depending on the repository and Git version, but these are important parts to understand.
The easiest way to understand the current state of the repository is to use:
git status
It can show the current branch and changes that are staged, unstaged or untracked.
Use the following command to view commits:
git log
The log helps you understand the history stored in the repository.
The files inside .git are managed by Git. Beginners should normally use Git commands rather than manually editing these internal files.
.git directory can damage or confuse a repository.
Project Files
↓
Working Directory
↓
git add
↓
Staging Area
↓
git commit
↓
Repository History
↓
Branches / Tags / References
Understanding this flow makes it easier to understand how Git manages project changes.
student-project/
│
├── .git/
│ ├── HEAD
│ ├── config
│ ├── index
│ ├── objects/
│ └── refs/
│
├── index.html
├── style.css
└── script.js
The project files are outside .git, while Git's repository information is stored inside .git.
A Git repository consists of your project files and the hidden .git directory. The working directory contains the files you edit, the staging area contains selected changes, and the repository stores committed history.
Working Directory
↓
git add
↓
Staging Area
↓
git commit
↓
Git Repository
The .git directory contains important internal information such as repository configuration, references, objects, the index and HEAD information.
git init.Question: Which directory contains Git's internal repository information?