6. Unveiling Git
Pratyay: Hey there! Welcome back to Tech Bytes with Pratyay—your weekly shortcut to computer science on the go.
(Slightly upbeat, friendly music starts and fades to a low background hum)
Pratyay: Let me take you back to my early days of coding. Picture this: it’s 2 AM, I’m working on a personal project, and I finally get a new feature to work. To save my progress, I do what any sane person would do, right? I copy the entire project folder and name it Project_v2_works.zip
.
An hour later, I try to add another feature, and everything breaks. Everything. I can’t figure out how to fix it. So I frantically go back to my zip folders. I unzip Project_v2_works.zip
, but wait… did I make a small improvement after that? Maybe the real version is in Project_v3_final.zip
? Or was it Project_final_final_I_swear_this_is_it.zip
?
I ended up so frustrated, lost in a maze of my own folders, that I just shut my laptop and gave up for the night. If that story sounds even vaguely familiar, then you already know why today's topic is a lifesaver.
Today, we’re popping the hood on Git. We all use it, but how does it actually work? We’ll go from its surprising origin story to how it magically knows every single change you’ve made, and what’s really happening when you type git push
.
So, first up: What is Git?
At its core, Git is a Distributed Version Control System. Let's break that down. "Version Control" means it tracks the history of your files. "Distributed" means that instead of one central server holding the entire project history, every single developer has a full copy of the project and its history on their own machine. This makes it incredibly fast and flexible.
But the idea for Git didn't come from a big corporation. It came from a problem.
Back in the early 2000s, the Linux kernel was managed using a proprietary tool called BitKeeper. In 2005, the company behind BitKeeper revoked the free license for the Linux community.
The creator of Linux, the one and only Linus Torvalds, was faced with a huge problem. He had thousands of developers around the world who needed to collaborate on an incredibly complex project, and now they had no tool to do it. So, what did he do? In true genius fashion, he took a weekend off, coded the first prototype of a new tool, and named it Git.
And here’s a fun fact: "Git" is British slang for an "unpleasant person." Linus Torvalds famously joked, "I'm an egotistical bastard, so I name all my projects after myself. First Linux, now Git."
So, that’s the why.
Now for the how. How does Git actually know the changes you’ve made?
You might think it just keeps a list of differences—or 'diffs'—between files. Line 5 was changed, Line 10 was added.
But that's not the whole story, and it would be very inefficient for a huge project.
Instead, Git thinks in snapshots.
Imagine your project is a landscape. Every time you make a commit
, Git doesn't just write down what changed. It takes a full photograph—a snapshot—of every single file in your project at that exact moment.
Now you're thinking, "Doesn't that take up a huge amount of space?"
This is where the magic comes in. If a file has not changed from one commit to the next, Git doesn't store a new copy of that file. It simply includes a link, or a pointer, to the previous identical file it has already stored.
So, your project history isn't a long list of edits; it's a beautiful, efficient chain of snapshots, each one linked to the one before it, creating a timeline you can travel through at any time.
Now, any tool built for collaboration has to answer a critical question: what happens when two people change the exact same thing at the exact same time? In software, this could be two developers editing the same line of code in the same file. This is where you encounter one of Git's most famous—and sometimes feared—features: the merge conflict.
Let's go back to our library analogy. Imagine you're tasked with editing a specific sentence in Chapter 3. At the same time, your colleague, Sarah, is also editing that exact same sentence. When the time comes to merge both of your changes into the library's master copy, Git faces a dilemma. It sees two different versions of the same line and can't read your minds to know which one is correct.
This is a merge conflict.
Git’s response is brilliant. Instead of guessing and potentially deleting someone's work, it just pauses the process. It literally edits the conflicted file, Chapter3.txt
, and inserts special markers: <<<<<<< HEAD
, ======
and >>>>>>>
.
These markers are Git’s way of saying, "Hey, human, I need your help! Here’s the version you wrote (HEAD
), and here’s the version Sarah wrote that I'm trying to merge in. I'm leaving both in the file. You are the editor. You need to decide what the final version of Chapter 3 should look like."
Your job is to open that file, look at both sets of changes, delete the version you don't want (or combine them into something new), and then remove Git's special markers. Once you’ve cleaned it up, you save the file and tell Git you've resolved the conflict, usually by committing the fix.
So, a merge conflict isn't an error to be afraid of. It’s a crucial safety feature. It's Git's way of preventing developers from accidentally overwriting each other's work and forcing them to communicate. It's the core of safe, collaborative coding.
Wrapping this up: Git's behind-the-scenes magic is a powerful system that treats your project's history not as a list of edits, but as a series of complete snapshots, making collaboration fast, safe, and efficient.
That’s your byte-sized note from Tech Bytes with Pratyay. Today we went over an application of computer science we all use but rarely understand how it works in the background.
Next week, we’ll dive into a case study, we all use social media, it's addicting. But why is it the case? Is it okay to blame YOUR will power for not being able to control the urges? and the beautiful design behind every single element that keeps us hooked!
If something clicked for you, don’t forget to follow, like, and share! What’s a tech concept you wish was explained better? Tell me your story, and let’s bust more tech myths together.