Skip to content

What Is a Repository?

Understanding the Git repository — the .git folder, working directory, and staging area.

What you'll learn

  • What a repository (repo) is and what it contains
  • The three areas: working directory, staging area, and history
  • What the hidden .git folder does
  • The lifecycle of a file: untracked, staged, committed

Concept

What Is a Repository?

A repository (often shortened to repo) is a directory that Git is tracking. It contains your project files plus all the history of changes you have made.

You can think of a repository as a folder where Git has set up shop — it watches every file inside, lets you save snapshots (commits), and remembers the entire history of your project.

The Three Areas

Git divides your project into three logical areas:

  1. Working directory — the actual files you see and edit in your editor. This is where you write code.
  1. Staging area (index) — a temporary holding area where you place files you want to include in your next commit. You add files here with git add.
  1. Repository (.git directory) — the permanent history. When you git commit, the staged snapshot is saved here. This is where all commits, branches, and tags live.

The flow is:

Working Directory  →  git add  →  Staging Area  →  git commit  →  Repository

The .git Folder

When you run git init, Git creates a hidden .git folder inside your project directory. This folder contains everything Git knows about your project:

  • objects/ — all the compressed snapshots and file contents
  • refs/ — pointers to commits (branches and tags)
  • HEAD — a file pointing to the current branch
  • config — repository-specific settings

Never delete or manually edit the .git folder — doing so can corrupt your repository and lose all history. If you want to stop tracking a project, you can safely delete the .git folder, but you will lose all history.

File Lifecycle

A file in a Git repository goes through states:

  • Untracked — Git sees the file but is not tracking it yet (git add to track)
  • Staged — the file is in the staging area, ready to commit
  • Committed — the file is safely stored in the repository history
  • Modified — a tracked file has been changed since the last commit
untracked → (git add) → staged → (git commit) → committed
committed → (edit file) → modified → (git add) → staged → (git commit) → committed

Understanding these states is the key to knowing what git status is telling you.

Example

              # Create a new directory and turn it into a Git repository
mkdir my-project
cd my-project
git init

# Git creates a hidden .git folder — let's look inside
ls -la .git

# Create a file — it is untracked
echo "Hello Git" > README.md

# Check the status — Git sees the file but is not tracking it
git status

# Stage the file — now it is in the staging area
git add README.md

# Check the status again — the file is now staged
git status

# Commit the file — now it is in the repository history
git commit -m "Add README"

# Check the status — working tree is clean
git status
            

This walks through the full lifecycle: creating a repo, adding a file, staging it, and committing. Run git status after each step to see how the file moves between states.

Try it

  • .gitignore Generator

    Create a .gitignore to keep unwanted files out of your repo.

  • Code Diff

    Compare two versions of a file — similar to what Git shows on commit.

Common mistakes

The mistake

Deleting the .git folder and losing all project history

The fix

The .git folder contains your entire repository history. Never delete it unless you intentionally want to stop tracking the project. Make regular backups or push to a remote.

The mistake

Confusing the staging area with the repository

The fix

Files in the staging area (after git add) are NOT yet saved in history. They are only saved when you run git commit. If you edit a staged file, you need to git add it again.

Related Cheatsheets

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors