What is Git?
Git is a distributed version control system (DVCS) that tracks every change you make to your code, documents, or configuration files. Unlike saving copies of files manually (report-v2-final-REAL.docx), Git records the full history of every modification, who made it, when, and why — letting you travel back in time, work in parallel, and collaborate without stepping on each other's work.
Why Git Matters
Whether you're a solo developer, a DevOps engineer, or a team of 500, Git solves fundamental problems:
| Problem Without Git | How Git Solves It |
|---|---|
| "Which version is the latest?" | Every commit is timestamped and ordered — history is always clear |
| "Who changed this line and why?" | git blame shows the author, date, and commit message for every line |
| "I broke everything, how do I go back?" | git revert or git checkout restores any previous state instantly |
| "Two people edited the same file" | Git merges changes automatically, or flags conflicts for manual resolution |
| "My laptop died, I lost everything" | Every clone is a full backup — push to GitHub and you're safe |
| "I want to experiment without risk" | Branches let you try anything without touching the main codebase |
How Git Thinks: Snapshots, Not Diffs
Most version control systems store differences (deltas) between versions. Git is fundamentally different — it stores snapshots of your entire project at each commit.
flowchart TB
subgraph "Traditional VCS (Delta-based)"
A1["Version 1<br/>File A, File B, File C"] --> A2["Δ2: Changed File A"]
A2 --> A3["Δ3: Changed File B"]
A3 --> A4["Δ4: Changed A + C"]
end
subgraph "Git (Snapshot-based)"
B1["Commit 1<br/>Snapshot: A₁, B₁, C₁"] --> B2["Commit 2<br/>Snapshot: A₂, B₁, C₁"]
B2 --> B3["Commit 3<br/>Snapshot: A₂, B₂, C₁"]
B3 --> B4["Commit 4<br/>Snapshot: A₃, B₂, C₂"]
end
If a file hasn't changed, Git doesn't store it again — it stores a pointer to the previous identical version. This makes Git incredibly fast and space-efficient, while still giving you instant access to any version of any file.
The Three-Tree Architecture
Git uses three "areas" to manage your files. Understanding this mental model is the key to mastering Git:
flowchart LR
A["Working Directory<br/>(your files on disk)"] -->|git add| B["Staging Area<br/>(index / planned changes)"]
B -->|git commit| C["Repository<br/>(.git / permanent history)"]
C -->|git checkout| A
| Area | What It Is | What Lives Here |
|---|---|---|
| Working Directory | Your actual files on disk — what you see in your editor | Untracked and modified files |
| Staging Area (Index) | A "preview" of your next commit — you choose exactly what goes in | Files you've git add-ed |
Repository (.git/) | The permanent history — all commits, branches, tags | Everything you've committed |
Practical Example
# 1. You edit a file → Working Directory changes
echo "Hello World" > README.md
# 2. You stage the change → Staging Area
git add README.md
# 3. You commit → Repository (permanent)
git commit -m "Add README"
Distributed: Every Clone Is Complete
Unlike centralized systems (SVN, Perforce), every Git clone contains the entire history:
flowchart TB
subgraph "Centralized VCS"
SC["Central Server<br/>(single point of failure)"]
C1["Developer 1<br/>(latest files only)"] --> SC
C2["Developer 2<br/>(latest files only)"] --> SC
end
subgraph "Git (Distributed)"
GH["GitHub<br/>(remote, full history)"]
G1["Developer 1<br/>(full history)"] <--> GH
G2["Developer 2<br/>(full history)"] <--> GH
G1 <-.->|"can sync directly"| G2
end
Benefits of distributed:
- Work offline — commit, branch, view history without internet
- No single point of failure — if the server dies, any clone can restore it
- Faster operations — most commands run locally (no network round-trip)
Git vs GitHub
A common confusion: Git ≠ GitHub.
| Aspect | Git | GitHub |
|---|---|---|
| What | Version control software | Cloud hosting platform for Git repos |
| Where | Runs on your local machine | Runs on github.com |
| Cost | Free, open-source | Free tier + paid plans |
| Purpose | Track changes, branch, merge | Collaborate, review code, automate (CI/CD) |
| Alternatives | — (Git is the standard) | GitLab, Bitbucket, Gitea, Codeberg |
You can use Git entirely without GitHub. GitHub adds collaboration features (pull requests, issues, actions) on top of Git's version control.
Core Concepts at a Glance
| Concept | One-Line Explanation |
|---|---|
| Repository (repo) | A project folder tracked by Git (contains .git/ directory) |
| Commit | A snapshot of your project at a point in time |
| Branch | A parallel line of development (e.g., main, feature/login) |
| Merge | Combining changes from one branch into another |
| Remote | A copy of your repo on another machine (e.g., GitHub) |
| Clone | Downloading a full copy of a remote repository |
| Push | Uploading your local commits to a remote |
| Pull | Downloading remote commits to your local repo |
| Staging | Selecting which changes to include in your next commit |
| HEAD | A pointer to your current position in the history |
When to Use Git
| Scenario | Use Git? | Why |
|---|---|---|
| Any software project | ✅ Always | Track every change, collaborate safely |
| Configuration files (nginx, docker) | ✅ Yes | Version your infrastructure |
| Documentation / writing | ✅ Yes | Track drafts, collaborate with reviewers |
| Databases (binary data) | ⚠️ Partially | Git handles text well, binary poorly — use Git LFS |
| Large media files (video, PSD) | ❌ Not ideal | Use Git LFS or dedicated asset management |
| Temporary scratch files | ❌ No | Use .gitignore to exclude them |
Best Practices (Preview)
- Commit often — Small, frequent commits are easier to understand and revert
- Write meaningful messages — "Fix login bug" not "update stuff"
- Use branches — Never work directly on
mainfor features - Pull before push — Avoid merge conflicts by staying up-to-date
- Use
.gitignore— Keep secrets, build artifacts, and temp files out of history
What's Next
Now that you understand what Git is and why it matters:
- Git vs Other VCS — How Git compares to SVN, Mercurial, and others
- How Git Works Internally — SHA hashing, object storage, and the DAG
- Installation & Setup — Get Git running on your system