Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Version Control Systems",
"position": 3,
"link": {
"type": "generated-index",
"description": "Learn how to manage your code history, collaborate with others, and never lose a line of code again. This is the most essential skill for any modern developer."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
---
sidebar_position: 6
title: "Git Setup & Your First Repo"
sidebar_label: "6. Setup Guide"
description: "Step-by-step instructions to install Git, configure your profile, and push your first project to GitHub."
---

It’s time to stop reading and start doing! In this guide, we will transform your computer into a developer workstation.

## Step 1: Install Git

First, we need to get the Git engine running on your machine.

<Tabs>
<TabItem value="windows" label="🪟 Windows" default>

1. Download the **[Git for Windows](https://git-scm.com/download/win)** installer.
2. Run the `.exe` file.
3. **Important:** When asked about the "Default Editor," you can choose **Visual Studio Code**.
4. Keep all other settings as "Default" and click **Install**.

</TabItem>
<TabItem value="mac" label="🍎 macOS">

1. Open your Terminal (Command + Space, type `Terminal`).
2. Type `git --version` and hit Enter.
3. If you don't have it, a popup will ask you to install **Xcode Command Line Tools**. Click **Install**.
4. Alternatively, if you use [Homebrew](https://brew.sh/), run: `brew install git`.

</TabItem>
<TabItem value="linux" label="🐧 Linux">

Open your terminal and run the command for your distribution:
* **Ubuntu/Debian:** `sudo apt install git-all`
* **Fedora:** `sudo dnf install git-all`

</TabItem>
</Tabs>

## Step 2: Configure Your Identity

Git needs to know who is making changes. Open your terminal (or **Git Bash** on Windows) and type these two lines:

```bash
git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"
```

*Note: Use the same email address you plan to use for your GitHub account.*

## Step 3: Create Your First Repository

Let's create a "Hello World" project and track it with Git.

### 1. Create a Folder

```bash
mkdir my-first-repo
cd my-first-repo
```

### 2. Initialize Git

This creates a hidden `.git` folder. This is where the "Time Machine" lives!

```bash
git init
```

### 3. Create a File

Create a simple file named `hello.txt` and add some text to it.

### 4. The Magic Sequence (Add & Commit)

```bash
# Add the file to the Staging Area
git add hello.txt

# Save the snapshot to the Local Repository
git commit -m "feat: my very first commit"
```

## Step 4: Connect to GitHub

Now, let's put your code in the cloud so the world can see it.

1. Go to **[GitHub.com](https://github.com)** and create a free account.
2. Click the **+** icon in the top right and select **New Repository**.
3. Name it `my-first-repo` and click **Create repository**.
4. GitHub will give you a "Remote URL" (it looks like `https://github.com/your-username/my-first-repo.git`).

**Run these commands in your terminal to link your computer to GitHub:**

```bash
# Link your local repo to the cloud
git remote add origin https://github.com/your-username/my-first-repo.git

# Rename your main branch to 'main' (standard practice)
git branch -M main

# Upload your code!
git push -u origin main
```

## How to Check Your Work

Refresh your GitHub repository page. You should see your `hello.txt` file sitting there!

```mermaid
sequenceDiagram
participant PC as Your Computer (Local)
participant GH as GitHub (Cloud)

PC->>PC: git init
PC->>PC: git add & commit
PC->>GH: git push
GH-->>PC: Successfully uploaded!

```

## Common Commands Cheat Sheet

| Command | Purpose |
| --- | --- |
| `git status` | See which files are modified or staged. |
| `git log` | See the history of all your commits. |
| `git diff` | See exactly what lines changed in your files. |
| `git branch` | List your current branches. |

:::success 🎉 Congratulations!
You are now officially using Version Control. You have a local history on your computer and a backup in the cloud. You are ready to start building real backend applications!
:::
101 changes: 101 additions & 0 deletions absolute-beginners/backend-beginner/version-control-systems/git.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
sidebar_position: 2
title: "Git - The Industry Standard"
sidebar_label: "2. Git"
description: "Master the world's most popular Distributed Version Control System."
---

**Git** is a distributed version control system. This means that every developer’s computer contains the **entire history** of the project. It is fast, efficient, and used by millions of companies including Google, Microsoft, and Netflix.

## The Git Workflow

Before typing commands, you must understand the **Three Stages** of Git. Think of it like taking a professional photo:

1. **Working Directory:** You are posing for the photo (Writing code).
2. **Staging Area:** You are "frozen" in the frame, but the shutter hasn't clicked (Preparing code).
3. **Local Repository:** The photo is saved to the memory card (Saved forever).

```mermaid
graph LR
A[Working Directory] -->|git add| B[Staging Area]
B -->|git commit| C[Local Repository]
C -->|git push| D[Remote/GitHub]
```

## Essential Git Commands

How do you actually use it? You can choose between using the **Terminal** (for power users) or a **GUI** (for a visual experience).

<Tabs>
<TabItem value="terminal" label="💻 Terminal" default>

```bash
# 1. Start a new repository
git init

# 2. Check what has changed
git status

# 3. Add a specific file to the 'Staging Area'
git add index.js

# 4. Save the snapshot with a message
git commit -m "feat: add user login logic"

# 5. Send your code to GitHub
git push origin main

```

</TabItem>
<TabItem value="gui" label="🖱️ Desktop App / VS Code">

1. **VS Code:** Click the "Source Control" icon on the left sidebar.
2. **Staging:** Click the **+** icon next to the file name.
3. **Commit:** Type your message in the box and click **Commit**.
4. **Sync:** Click **Sync Changes** to push to the cloud.

</TabItem>
</Tabs>

## Branching: Parallel Realities

The most powerful feature of Git is **Branching**.

Imagine you want to add a "Dark Mode" to your app, but you don't want to risk breaking the current working version. You create a branch.

```mermaid
gitGraph
commit id: "Initial"
commit id: "Setup API"
branch feature-dark-mode
checkout feature-dark-mode
commit id: "Add CSS"
commit id: "Add Toggle"
checkout main
merge feature-dark-mode
commit id: "Launch v1.1"

```

## Why CodeHarborHub Recommends Git

* **Offline Capability:** You can save your progress while traveling or if your internet is down.
* **Safety:** Every "Commit" is a checksum (a unique ID). It is almost impossible to lose data or corrupt the history.
* **The Ecosystem:** Since Git is the standard, it integrates with every major tool like **VS Code**, **Docker**, and **Vercel**.

## Recommended Resources

* **[Oh My Git!](https://ohmygit.org/)**: An open-source game to learn Git visually.
* **[Git Cheat Sheet by GitHub](https://education.github.com/git-cheat-sheet-education.pdf)**: A handy PDF to keep on your desk.

## Summary Checklist

* [x] I understand the 3 stages: Working Directory, Staging, and Repository.
* [x] I can initialize a project with `git init`.
* [x] I know that `git add` prepares my changes and `git commit` saves them.
* [x] I understand that branches allow for safe experimentation.

:::tip Pro-Tip
Always write **clear commit messages**. Instead of writing "Fixed stuff," write "fix: resolve login button alignment on mobile." Your future self (and your team) will thank you!
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
sidebar_position: 1
title: "Introduction to Version Control"
sidebar_label: "1. What is VCS?"
description: "Understand the concept of Version Control Systems and why they are the Time Machine of software development."
---

Imagine you are working on a massive backend project. You’ve spent 10 hours writing the perfect API. Suddenly, you make a small change, and the entire server crashes. You try to undo it, but you've already saved the file. You can't remember what the code looked like before.

**This is where Version Control Systems (VCS) save your life.**

## 🧐 What is Version Control?

A **Version Control System** is a software tool that tracks every single change you make to your code. It’s like a "Save Game" feature in a video game. If you run into a boss (a bug) that you can't beat, you can simply reload your previous save point.

### The "Time Machine" Analogy
Without VCS, your folder looks like this:
* `server.js`
* `server_final.js`
* `server_final_v2.js`
* `server_DO_NOT_DELETE.js`

With VCS, you have **one** file named `server.js`, but you can travel back in time to see exactly what that file looked like 5 minutes, 5 days, or 5 months ago.

## Why is it Essential?

### 1. Collaboration (The "No-Clash" Rule)
In a professional setting, five developers might be editing the same file at the same time. A VCS intelligently **merges** their changes together so no one's work is overwritten.

### 2. Traceability (The "Who Did This?" Rule)
VCS keeps a log of **Who** changed **What** and **Why**. This isn't for blaming people; it's for understanding the logic behind a change months after it happened.

### 3. Branching (The "Parallel Universe" Rule)
You can create a **Branch** to test a crazy new idea. If the idea fails, you just delete the branch, and your main code remains perfectly safe. If it works, you merge it back into the main project.

## Two Types of VCS

There are two main ways these systems are built:

### A. Centralized VCS (CVCS)
There is one single central server that stores all the versions. Developers "check out" files from that server.
* **Example:** SVN (Subversion).
* **Cons:** If the server goes down, no one can save their work.

### B. Distributed VCS (DVCS)
Every developer has a **full copy** of the entire project history on their own computer.
* **Example:** Git, Mercurial.
* **Pros:** You can work offline, and if the main server dies, any developer's computer can be used to restore it.

## Current Market Favorites

Currently, the world of programming is dominated by these three:

1. **Git:** The undisputed king (Distributed).
2. **SVN:** Still used in some older, large corporate environments (Centralized).
3. **Mercurial:** A friendly alternative to Git (Distributed).

## Summary Checklist

* [x] I understand that VCS is a history tracker for my code.
* [x] I know that "Branching" allows me to experiment safely.
* [x] I understand that most modern systems are "Distributed."
* [x] I am ready to learn the most popular tool in the world: **Git**.

:::tip Fun Fact
The most popular VCS today, **Git**, was created by **Linus Torvalds** in just 10 days because he was unhappy with the other tools available for building the Linux kernel!
:::
Loading