Skip to main content

Command Palette

Search for a command to run...

Git for Beginners

Published
•4 min read•View as Markdown

You must NOT reverse engineer it!

These were the words of the company behind a very popular version control system back in the 2000s: BitKeeper.

BitKeeper was proprietary software by a company called BitMover. The founder of BitKeeper, Larry McVoy, allowed it to be used freely on open source projects including the biggest of all, LINUX on one condition: that they could not reverse engineer it, nor could they contribute to competing version control systems.

But as we know in tech, everything that can be reverse engineered will be reverse engineered. Cut to the day when a developer (Andrew Tridgell) actually did it. The access to BitKeeper was revoked almost overnight. The biggest project in the world, the Linux Kernel, was left with no version control system.

What happens next? Here is where the legend enters the story. Linus Torvalds, the creator of Linux, decided to fix the problem himself. He disappeared for a weekend and created his own version control system in just 10 days. He named it Git.

What is Git?

Git is a distributed version control system. We learned about what a version control system is in the last blog, but what is "distributed"?

In the old days (Centralized Version Control), there was just one source of truth: 1 server. If that server died, everything was lost.

In Git, distributed means everyone has the entire copy of the project history and version control locally on their own machine. If the main server blows up, any developer's computer can restore the whole history. Hence the name: distributed.

Why Git is Used?

So why did the whole world switch to Git? It wasn't just because Linus made it.

  1. Speed: Since you have everything on your local computer, you don't have to wait for a network request every time you want to save a version. It’s blazing fast.

  2. Offline Work: You can code on a plane, in a basement, or on a mountain. You can commit your changes without internet, and just sync up when you're back online.

  3. Branching is Inexpensive: This is the defining feature. In old systems, creating a "branch" (a parallel version of your code to test features) was a nightmare. In Git, it's instant. You can make a mess in a new branch, and if it doesn't work, just delete it. Your main code stays safe.

Git Core Terminologies

  • Repository (Repo): This is just the folder where your project lives. It’s the bucket that holds all your files and the history of changes.

  • Stage (Staging Area): Think of this like a shopping cart. You pick the files you want to save (add them to the cart), but you haven't bought them yet. You are just preparing them.

  • Commit: This is the checkout. When you "commit," you are taking a snapshot of everything in your staging area and saving it permanently in the history. It's like a "Save Point" in a video game.

  • Branch: A parallel universe. You can diverge from the main code, build a feature, breaks things, and then merge it back only when it works.

Common Git Commands

We don't need to memorize the whole manual. Most of the time, we will only use these:

  • git init
    The start button. turns your current folder into a Git repository.

  • git add <file>
    Moves changes from your working directory to the Staging Area.
    (Pro tip: git add . adds everything at once).

  • git commit -m "message"
    Saves the snapshot. Always write a message so you know what you did later!

  • git status
    The "Where am I?" command. It tells you what files are changed and what isn't saved yet.

  • git push ( But How can we share the code and code history, Just upload the Repo to a cloud ! )
    Uploads your local commits to the cloud (like GitHub or GitLab will talk about them in later blogs).

  • git pull
    Downloads the latest changes from the cloud to your machine.

Demo WorkFlow

# 1. Start the engine (do this once per project)
git init

# (You create a file called 'script.py'...)

# 2. Check what's up (Git sees the new file in red)
git status

# 3. Stage everything (Add all files to the "cart")
git add .

# 4. Save the first snapshot
git commit -m "started the project"

# --- LATER: YOU EDIT THE FILE ---

# 5. Check status (Git sees 'script.py' is modified)
git status

# 6. Stage the updates
git add .

# 7. Save the second snapshot (History grows)
git commit -m "fixed a bug in the script"

# --- SHARING (OPTIONAL) ---

# 8. Link to the cloud (GitHub/GitLab) - only done once
git remote add origin https://github.com/yourname/repo.git

# 9. Upload your history to the server
git push -u origin main

TL;DR

Git was born out of necessity when the Linux team lost their tools. It differs from old systems because it is distributed(everyone has a copy). We use it because it's fast, works offline, and handles branching like a champ.

To start, just remember:

git init 

git add {fileName}

got commit -m "first commit"