Skip to content

๐ŸŽ“ Git Introduction โ€‹

What is Git? โ€‹

Imagine you're writing a novel. By the time you reach Chapter 50, you suddenly feel that the ending you wrote in Chapter 3 was actually better and want to revert โ€” but you've already changed it 8 times and can't remember what you originally wrote.

If only you had a "time machine" that lets you freely travel between any version... Well, Git is the time machine of the code world.

Git is a Distributed Version Control System (DVCS), created by Linus Torvalds, the father of Linux, in 2005. That's right, the same person who created Linux โ€” and rumor has it he wrote the first version of Git in just about 10 days. We can only dream of being that brilliant.

๐Ÿ’ก Tip: In simple terms: Git is a "save system" for your code. In a video game, you save your progress at each level โ€” Git works the same way, except it saves your code and lets you return to any save point at any time.

Why not just "copy folders" to manage versions? โ€‹

I know what you're thinking: why not just copy the folder and name them project_v1, project_v2, project_final, project_final_for_real, project_final_never_touching_again...

Don't laugh, I actually did this back in the day. What happened?

  • My hard drive was stuffed with 20 nearly identical folders, running out of space
  • Couldn't remember which version changed what
  • Want to merge changes from two versions? Manually? Yeah right
  • Collaborating with teammates? Sending zip files back and forth? Give me a break

Git elegantly solves all of this.

Centralized vs Distributed โ€‹

Before Git, the mainstream version control systems were centralized, like SVN and CVS. They worked like a class sharing a single notebook:

text
๐Ÿ“ฆ Centralized Version Control (e.g., SVN)

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Central Server  โ”‚  โ† All version history lives here
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚ Network
  โ”Œโ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”
  โ”‚    โ”‚    โ”‚
  โ–ผ    โ–ผ    โ–ผ
Alice  Bob  Charlie   โ† Everyone only has the latest version

The problem is obvious: server goes down = everyone's work is gone. Network goes down = can't work.

text
๐ŸŒ Distributed Version Control (e.g., Git)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Alice โ”‚    โ”‚  Bob  โ”‚    โ”‚Charlieโ”‚
  โ”‚(Full  โ”‚    โ”‚(Full  โ”‚    โ”‚(Full  โ”‚
  โ”‚History)โ”‚โ†โ†’ โ”‚History)โ”‚โ†โ†’ โ”‚History)โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  Everyone has the full repository! Works offline!

๐Ÿ“ Note: Remember this key difference: centralized systems store only "deltas" (differences), while Git stores "snapshots." Each commit is like taking a photograph, recording the complete state of all files at that moment. While this sounds like it takes more space, Git is smart โ€” unchanged files are stored as pointers, so there's no duplication.

Snapshots vs Deltas โ€‹

ComparisonSnapshots (Git)Deltas (SVN/CVS)
Storage methodSaves complete snapshot per commitSaves differences from previous version
Viewing historyDirect access, extremely fastRequires rebuilding from the beginning
Branch costNearly zero (just creates a pointer)Needs to copy entire directory
Offline workFully supportedNot supported
Data integritySHA-1 hash verificationRelies on server

Git's Design Philosophy โ€‹

Understanding these philosophies will make Git's command design feel very logical:

  • Integrity first โ€” Git uses SHA-1 hashes to identify everything; no change can go undetected
  • Append-only โ€” Git almost never deletes data; most operations just add new data
  • Local-first โ€” The vast majority of operations happen locally, making them blazing fast
  • Three-state design โ€” Modified, Staged, Committed (covered in detail later)