Skip to main content

Introduction

To use Git effectively, you only need to understand three concepts:
  • Working Directory
  • Staging Area (Index)
  • Repository
These three concepts explain how Git tracks and saves changes.

Understanding the Repository

After running:
Git creates a hidden folder named:
The .git folder is called the Local Repository. It stores Git’s database, including:
  • Commit history
  • Staging Area (Index)
  • Branches
  • HEAD (latest commit reference)
  • Repository configuration
Your source code is not stored directly inside .git. It remains in your project folder (Working Directory).

The Three States of a File

After the first commit, a file can exist in three different states.
Note Both the Staging Area and the Latest Commit are physically stored inside the Repository (.git).

How These States Evolve

Before git init

Only one copy of your files exists.
No repository exists.

After git init

The repository exists, but:
  • No commits
  • No history
  • No staged files
Your files still exist only in the Working Directory.

After git add

The file is ready to be committed.

After the First Commit

From now on, these three states may be different.

Why Do We Need the Staging Area?

Suppose you modified three files.
Only login.py is complete. You can choose only that file.
Only login.py becomes part of the commit. The Staging Area lets you choose exactly what should go into the next commit.

What Does git status Do?

git status compares two things.

Comparison 1

If they differ, Git reports:

Comparison 2

If they differ, Git reports:
git status only compares these states. It does not modify or store anything.

What Happens During git add?

Assume the latest commit contains:
You edit the file.
Current state:
Run:
Now:
The Staging Area is updated.

What Happens During git commit?

Run:
Now:
Git creates a new commit and updates the latest committed version.

What Happens During git push?

Git uploads your Local Repository to the Remote Repository.
GitHub stores the same repository and reconstructs your files when you browse them in the browser.

Complete Git Workflow

Common Git Commands

Key Takeaways

  • The Working Directory contains the files you edit.
  • The Repository (.git) stores Git’s complete database.
  • The Staging Area (Index) is part of the Repository.
  • The Latest Commit (HEAD) is also stored inside the Repository.
  • git add updates the Staging Area.
  • git commit creates a new commit from the staged files.
  • git status compares the Working Directory, Staging Area, and Latest Commit.
  • git push uploads your Local Repository to GitHub.

Remember

  • Working Directory → Files you edit.
  • Staging Area (Index) → Files selected for the next commit.
  • Latest Commit (HEAD) → Most recently committed version.
  • Repository (.git) → Git’s database containing the Staging Area, commit history, branches, and other metadata.