Git Core Concepts
Git does not work like a regular folder on a computer. It has its own way of organizing and tracking files. Before jumping into commands, it is important to understand these core ideas. Once these concepts are clear, everything else in Git will make much more sense.
The Three Areas of Git
Every file in a Git project lives in one of three areas at any given time. Understanding these areas is the most important concept in Git.
┌─────────────────────┐ git add ┌──────────────────┐ git commit ┌──────────────────┐
│ Working Directory │ ─────────────► │ Staging Area │ ────────────────► │ Repository │
│ (Where you edit) │ │ (Preparation) │ │ (Saved History) │
└─────────────────────┘ └──────────────────┘ └──────────────────┘
1. Working Directory
This is the actual folder on the computer where all project files are present. When a file is opened and edited, the changes are happening in the Working Directory. Git knows about these changes, but has not saved them yet.
Real-life analogy: Think of a whiteboard. Writing on the whiteboard is instant and visible, but nothing is permanently saved yet.
2. Staging Area (also called the Index)
The Staging Area is like a waiting room. Before saving changes permanently, specific changes can be "staged" — selected and grouped together to be saved as one meaningful snapshot. This gives control over exactly what gets saved in each commit.
Real-life analogy: Think of packing a suitcase. Items from around the room are chosen (staging), and then the suitcase is zipped up (commit). Only the items placed in the suitcase get packed — not everything in the room.
3. Repository (The .git folder)
The Repository is where Git permanently stores all the snapshots (commits) of the project. It is contained inside a hidden folder called .git inside the project folder. This folder should never be deleted or manually edited — it is the entire history of the project.
Real-life analogy: Think of a photo album. Each commit is a photograph permanently stored in the album. At any time, an old photo can be looked at or the project can be restored to that exact state.
What is a Repository?
A repository (or "repo") is simply a folder where Git is actively tracking changes. It contains all the project files along with a hidden .git subfolder that stores the complete history, configurations, and branches.
There are two types of repositories:
- Local Repository — Stored on a personal computer
- Remote Repository — Stored on a server or platform like GitHub, GitLab, or Bitbucket
What is a Commit?
A commit is a saved snapshot of the project at a specific moment in time. Each commit records:
- What files changed
- What those changes were
- Who made the changes (name and email)
- When the changes were made (timestamp)
- A short message describing the change
- A unique ID (called a hash, e.g.,
a3f92b1)
Commits form a chain — each one points back to the previous one. Together they form the full history of the project.
Commit 1 ─── Commit 2 ─── Commit 3 ─── Commit 4 (Latest)
"Initial" "Add login" "Fix bug" "Update UI"
What is a Branch?
A branch is an independent line of work within a project. When a new branch is created, it starts as an exact copy of the current state of the project. Changes made on that branch do not affect other branches.
Real-life analogy: Think of a tree. The trunk is the main code (usually called main or master). When working on a new feature, a new branch grows out of the trunk. When the feature is done and tested, it is merged back into the trunk.
main branch: A ─── B ─── C ─────────────── G
\ /
feature branch: D ─── E ─── F
Branches are one of Git's most powerful features. They let different features, bug fixes, or experiments be worked on at the same time without interfering with the stable main code.
What is HEAD?
HEAD is a special pointer in Git that always points to the current position in the project — specifically, to the latest commit on the currently active branch. HEAD moves forward automatically with every new commit.
Think of HEAD as a "You Are Here" marker on a map.
main: Commit1 ─── Commit2 ─── Commit3
▲
HEAD (currently here)
What is a Remote?
A remote is a version of the repository stored somewhere else — typically on the internet, like GitHub. The remote allows teams to collaborate by pushing (uploading) and pulling (downloading) changes.
The default remote is typically named origin.
Local Computer Internet
┌────────────┐ push/pull ┌────────────────────┐
│ Local Repo │ ◄───────────── │ Remote Repo │
│ │ ──────────────►│ (GitHub/GitLab) │
└────────────┘ └────────────────────┘
What is the .git Folder?
When Git is initialized in a project folder, it creates a hidden folder called .git. This folder contains everything Git needs:
config— Local repository configurationHEAD— Pointer to the current branchobjects/— All the commit snapshots, file contents, and treesrefs/— Branch and tag referenceslogs/— History of where HEAD has pointed
Important: Never delete or manually edit the .git folder. Deleting it will erase the entire history of the project.
File States in Git
Every file in a Git project can be in one of these states:
| State | Meaning |
|---|---|
| Untracked | Git sees the file but is not tracking it yet (new file just created) |
| Tracked / Unmodified | Git is tracking the file and no changes have been made since the last commit |
| Modified | The file is tracked by Git and has been changed, but not yet staged |
| Staged | The file has been added to the Staging Area and is ready to be committed |
The Complete Git Flow — Step by Step
Here is how a typical Git workflow looks from start to finish:
1. Create or edit a file → File is in Working Directory (Modified/Untracked)
2. git add filename → File moves to Staging Area
3. git commit -m "message" → Staged files are saved permanently to Repository
4. git push → Commits are uploaded to the Remote Repository
Summary
Git organizes work into three areas: the Working Directory, the Staging Area, and the Repository. A commit is a saved snapshot. A branch is an independent line of development. HEAD always points to the current location. Understanding these five concepts — working directory, staging area, repository, commit, and branch — makes everything else in Git easy to follow.
