
Module 1 Lesson 1: What is Git and why use version control
Discover the foundations of version control. Learn how Git helps you track changes, collaborate, and travel back in time through your code's history.
Module 1 Lesson 1: What is Git and why use version control
In the world of software development, code is constantly changing. New features are added, bugs are fixed, and experiments are tried. But what happens if a "fix" breaks everything? Or what if you need to know who wrote a specific line of code six months ago?
This is where Version Control Systems (VCS) come in. In this lesson, we'll explore why version control is essential and why Git is the world's most popular tool for the job.
1. The Problem: "Saving as..."
Before version control, developers used the "Copy and Rename" strategy. You might have seen folders looking like this:
project_v1project_v2_finalproject_v2_final_REALLY_FINALproject_v2_final_for_production
This is messy, error-prone, and makes collaboration impossible. If two people work on the same folder, they will eventually overwrite each other's work.
2. The Solution: Version Control
A Version Control System is a tool that tracks every single change you make to a set of files. It’s like having a time machine for your project.
Key Benefits of VCS:
- Traceability: Every change is recorded with a name, date, and a message explaining "Why" the change was made.
- Reversibility: If you make a mistake, you can revert back to any previous state in seconds.
- Collaboration: Multiple people can work on the same files at the same time without stepping on each other's toes.
- Branching: You can create a safe "branch" to experiment with a new feature while keeping the main code stable.
graph TD
V1["Version 1: Basic App"] --> V2["Version 2: Added Login"]
V2 --> V3["Version 3: Fixed Bug #42"]
V3 --> V4["Version 4: Current State"]
V4 -- "Time Machine" --> V1
3. Enter Git
Git was created in 2005 by Linus Torvalds, the creator of Linux. He needed a system that could handle the massive scale and speed of the Linux kernel project.
Why Git is Special:
- Distributed: Unlike older systems (like SVN or CVS), Git is distributed. This means every developer has a full copy of the entire project history on their own machine. If the main server crashes, any developer's machine can restore it.
- Fast: Because most operations happen locally on your computer, Git is incredibly fast.
- Integrity: Git uses a mathematical algorithm (SHA-1 hashing) to ensure that no change can be "sneaked in" or corrupted without the system noticing.
Lesson Exercise
Goal: Reflect on your own "Version Control" history.
- Think of a time you accidentally deleted a file or "broke" a project you were working on.
- How did you fix it? (Did you have a backup? Did you have to rewrite it?)
- Now, imagine you had Git. Write down how much time and stress a "Git Revert" command would have saved you.
Observation: Understanding the pain of not having version control is the first step toward mastering Git.
Summary
In this lesson, we established:
- The "Manual" way of saving versions is dangerous and doesn't scale.
- Version control is a time machine that provides traceability, reversibility, and collaboration.
- Git is a distributed VCS known for its speed, integrity, and decentralized nature.
Next Lesson: We’ll compare Git to other systems and see why the "Distributed" approach won the version control wars.