Skip to main content

What is Git?

Quick Summary

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 GitHow 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
Why snapshots matter

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
AreaWhat It IsWhat Lives Here
Working DirectoryYour actual files on disk — what you see in your editorUntracked and modified files
Staging Area (Index)A "preview" of your next commit — you choose exactly what goes inFiles you've git add-ed
Repository (.git/)The permanent history — all commits, branches, tagsEverything 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.

AspectGitGitHub
WhatVersion control softwareCloud hosting platform for Git repos
WhereRuns on your local machineRuns on github.com
CostFree, open-sourceFree tier + paid plans
PurposeTrack changes, branch, mergeCollaborate, review code, automate (CI/CD)
Alternatives— (Git is the standard)GitLab, Bitbucket, Gitea, Codeberg
note

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

ConceptOne-Line Explanation
Repository (repo)A project folder tracked by Git (contains .git/ directory)
CommitA snapshot of your project at a point in time
BranchA parallel line of development (e.g., main, feature/login)
MergeCombining changes from one branch into another
RemoteA copy of your repo on another machine (e.g., GitHub)
CloneDownloading a full copy of a remote repository
PushUploading your local commits to a remote
PullDownloading remote commits to your local repo
StagingSelecting which changes to include in your next commit
HEADA pointer to your current position in the history

When to Use Git

ScenarioUse Git?Why
Any software project✅ AlwaysTrack every change, collaborate safely
Configuration files (nginx, docker)✅ YesVersion your infrastructure
Documentation / writing✅ YesTrack drafts, collaborate with reviewers
Databases (binary data)⚠️ PartiallyGit handles text well, binary poorly — use Git LFS
Large media files (video, PSD)❌ Not idealUse Git LFS or dedicated asset management
Temporary scratch files❌ NoUse .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 main for 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:

  1. Git vs Other VCS — How Git compares to SVN, Mercurial, and others
  2. How Git Works Internally — SHA hashing, object storage, and the DAG
  3. Installation & Setup — Get Git running on your system