Greetings, brave adventurer! Welcome to the Git Basics quest โ€” where youโ€™ll learn the version control system that powers nearly every software project on the planet. Git lets you track changes, collaborate with others, and fearlessly experiment with code knowing you can always roll back. This is the single most important tool in any developerโ€™s inventory.

๐ŸŒŸ The Legend Behind This Quest

Long before the age of cloud realms and container kingdoms, developers toiled in darkness โ€” overwriting each otherโ€™s scrolls, losing ancient code to careless keystrokes, and deploying broken incantations with no way to revert. Then came Git, forged by Linus Torvalds in the fires of the Linux kernel. It granted developers the power of perfect memory: every change recorded, every experiment safely branched, every mistake reversible. Today, Git is the foundation spell in every developerโ€™s grimoire โ€” and mastering it is your first step toward true digital sorcery.

๐Ÿ—บ๏ธ Quest Network Position

graph TB
    subgraph "Prerequisites"
        Terminal["๐ŸŒฑ Terminal Fundamentals"]
    end
    
    subgraph "Current Quest"
        Main["๐Ÿฐ Git Basics: Version Control"]
    end
    
    subgraph "Unlocked Adventures"
        GitAdv["๐Ÿฐ Advanced Git Workflows"]
        GitHub["๐Ÿฐ GitHub Collaboration"]
        CICD["โš”๏ธ CI/CD Pipelines"]
    end
    
    Terminal --> Main
    Main --> GitAdv
    Main --> GitHub
    GitHub --> CICD
    
    style Main fill:#ffd700,stroke:#333,stroke-width:2px
    style Terminal fill:#87ceeb
    style GitAdv fill:#98fb98
    style GitHub fill:#98fb98
    style CICD fill:#98fb98

๐ŸŽฏ Quest Objectives

Primary Objectives (Required for Quest Completion)

Secondary Objectives (Bonus Achievements)

Mastery Indicators

๐Ÿ—บ๏ธ Quest Prerequisites

๐Ÿ“‹ Knowledge Requirements

๐Ÿ› ๏ธ System Requirements

๐ŸŒ Install Git on Your Platform

๐ŸŽ macOS

# Git comes with Xcode CLI tools, or install via Homebrew
brew install git

# Verify installation
git --version

๐ŸชŸ Windows

# Install with winget
winget install Git.Git

# Or download from https://git-scm.com/download/win
# Verify installation
git --version

๐Ÿง Linux

# Ubuntu/Debian
sudo apt update && sudo apt install git

# Fedora
sudo dnf install git

# Verify installation
git --version

๐Ÿง™โ€โ™‚๏ธ Chapter 1: Your First Repository โ€” The Origin Story

Every great codebase starts with git init. In this chapter, youโ€™ll create your first repository and learn the fundamental rhythm of Git: edit โ†’ stage โ†’ commit.

โš™๏ธ Initial Configuration

Before your first commit, tell Git who you are:

# Set your identity (used in every commit)
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

# Set default branch name to 'main' (recommended)
git config --global init.defaultBranch main

# Verify your settings
git config --list

๐Ÿ—๏ธ Creating a Repository

# Create a new project directory
mkdir my-first-repo
cd my-first-repo

# Initialize Git tracking
git init

Expected Output:

Initialized empty Git repository in /path/to/my-first-repo/.git/

๐Ÿ“ The Git Workflow: Edit โ†’ Stage โ†’ Commit

# 1. Create a file
echo "# My First Project" > README.md

# 2. Check status โ€” see untracked files
git status

# 3. Stage the file (add to staging area)
git add README.md

# 4. Commit with a descriptive message
git commit -m "docs: add initial README"

๐Ÿ” Understanding the Three Areas

flowchart LR
    WD["๐Ÿ“‚ Working Directory\n(your files)"] -->|git add| SA["๐Ÿ“‹ Staging Area\n(index)"]
    SA -->|git commit| REPO["๐Ÿ›๏ธ Repository\n(.git history)"]
    REPO -->|git restore| WD
    SA -->|git restore --staged| WD
    
    style WD fill:#ffcccc,stroke:#cc0000
    style SA fill:#fff3cd,stroke:#cc9900
    style REPO fill:#d4edda,stroke:#28a745
Working Directory    โ†’    Staging Area    โ†’    Repository
   (your files)          (git add)           (git commit)
   
   Edit files here      Preview what        Permanent snapshot
                         will be committed   in project history

โœ… Chapter 1 Checkpoint: Repository Initiation

Validation โ€” confirm each before proceeding:

๐Ÿง  Knowledge Check:

โšก Quick Wins


๐Ÿง™โ€โ™‚๏ธ Chapter 2: Branching โ€” Parallel Universes

Branches let you work on features in isolation without affecting the main codebase. Think of them as parallel timelines you can merge together when ready.

๐Ÿ”€ Branch Lifecycle Diagram

gitGraph
    commit id: "init"
    commit id: "add README"
    branch feature/greeting
    checkout feature/greeting
    commit id: "add greeting"
    commit id: "update greeting"
    checkout main
    merge feature/greeting id: "merge feature"
    commit id: "continue work"

๐ŸŒฟ Creating and Switching Branches

# Create a new branch
git branch feature/greeting

# Switch to it
git switch feature/greeting

# Or create and switch in one command
git switch -c feature/greeting

๐Ÿ“ Making Changes on a Branch

# Add a new file on the feature branch
echo "Hello, World!" > greeting.txt
git add greeting.txt
git commit -m "feat: add greeting message"

# See all branches (* marks current)
git branch

๐Ÿ”€ Merging Branches

# Switch back to main
git switch main

# Merge the feature branch into main
git merge feature/greeting

# Delete the branch (optional, it's merged)
git branch -d feature/greeting

โš ๏ธ Handling Merge Conflicts

When two branches modify the same lines, Git asks you to resolve the conflict:

# Git marks conflicts in the file like this:
<<<<<<< HEAD
Current content on main
=======
Different content from feature branch
>>>>>>> feature/greeting

To resolve:

  1. Open the file in your editor
  2. Choose which content to keep (or combine both)
  3. Remove the conflict markers (<<<<<<<, =======, >>>>>>>)
  4. Stage and commit:
git add conflicted-file.txt
git commit -m "fix: resolve merge conflict in greeting"

โœ… Chapter 2 Checkpoint: Branch Mastery

Validation โ€” confirm each before proceeding:

๐Ÿง  Knowledge Check:

โšก Quick Wins


๐Ÿง™โ€โ™‚๏ธ Chapter 3: Remote Repositories โ€” Connecting to the World

Local Git is powerful, but the real magic happens when you connect to a remote like GitHub. This enables collaboration, backup, and sharing.

๐ŸŒ Local โ†” Remote Sync Flow

sequenceDiagram
    participant WD as ๐Ÿ’ป Working Directory
    participant LOCAL as ๐Ÿ›๏ธ Local Repo
    participant REMOTE as โ˜๏ธ GitHub (Remote)
    
    WD->>LOCAL: git commit
    LOCAL->>REMOTE: git push
    REMOTE->>LOCAL: git fetch
    LOCAL->>WD: git merge / git pull
    REMOTE-->>WD: git pull (fetch + merge)
    
    Note over WD,REMOTE: git clone creates LOCAL + WD from REMOTE

๐Ÿ”— Connecting to GitHub

# Add a remote repository
git remote add origin https://github.com/yourusername/my-first-repo.git

# Verify the remote
git remote -v

# Push your local commits to GitHub
git push -u origin main

๐Ÿ“ฅ Cloning an Existing Repository

# Clone a repository from GitHub
git clone https://github.com/username/repository.git

# This creates a local copy with full history
cd repository
git log --oneline

๐Ÿ”„ Staying in Sync

# Pull latest changes from remote
git pull origin main

# Push your changes to remote
git push origin main

๐Ÿ“„ The .gitignore File

Tell Git to ignore files that shouldnโ€™t be tracked:

# Create a .gitignore file
cat > .gitignore << 'EOF'
# OS files
.DS_Store
Thumbs.db

# Dependencies
node_modules/
__pycache__/

# Environment files
.env
*.log
EOF

git add .gitignore
git commit -m "chore: add gitignore for common files"

๐Ÿ“œ Exploring History

# View commit log
git log

# Compact one-line format
git log --oneline

# Visual branch graph
git log --oneline --graph --all

# Show changes in a specific commit
git show abc1234

โœ… Chapter 3 Checkpoint: Remote Connectivity

Validation โ€” confirm each before proceeding:

๐Ÿง  Knowledge Check:

โšก Quick Wins


๐Ÿง™โ€โ™‚๏ธ Chapter 4: Undoing Mistakes โ€” The Time-Travel Spells

Every adventurer makes mistakes. The mark of a true Git sorcerer is knowing how to undo them safely without destroying the timeline.

โ†ฉ๏ธ Undo Decision Flowchart

flowchart TD
    A{"What do you want to undo?"} -->|"Unstage a file\n(keep changes)"| B["git restore --staged file"]
    A -->|"Discard local changes\n(lose edits)"| C["git restore file"]
    A -->|"Undo last commit\n(keep changes)"| D["git reset --soft HEAD~1"]
    A -->|"Undo last commit\n(discard changes)"| E["git reset --hard HEAD~1"]
    A -->|"Create a new commit\nthat reverses a previous one"| F["git revert <commit-hash>"]
    
    style B fill:#d4edda,stroke:#28a745
    style C fill:#ffcccc,stroke:#cc0000
    style D fill:#fff3cd,stroke:#cc9900
    style E fill:#ffcccc,stroke:#cc0000
    style F fill:#d4edda,stroke:#28a745

๐Ÿ”ง Common Undo Operations

# Unstage a file (keep your edits)
git restore --staged README.md

# Discard changes in working directory (โš ๏ธ destructive)
git restore README.md

# Undo the last commit but keep changes staged
git reset --soft HEAD~1

# Undo the last commit AND discard all changes (โš ๏ธ destructive)
git reset --hard HEAD~1

# Safely reverse a published commit (creates a new commit)
git revert abc1234

โš ๏ธ Safety Rules

Command Destructive? Safe for shared branches?
git restore --staged No Yes
git restore Yes โ€” loses edits Yes
git reset --soft No โš ๏ธ Only before pushing
git reset --hard Yes โš ๏ธ Only before pushing
git revert No Yes โ€” preferred method

โšก Quick Wins


๐ŸŽฎ Implementation Challenges

Challenge 1: ๐ŸŸข The Chronicle Keeper (๐Ÿ• 20 minutes)

Objective: Build a personal project repository with a clean, professional commit history.

Acceptance Criteria:

Verification Command:

# Should show exactly 5 commits
git log --oneline | wc -l

# All commits should follow conventional format
git log --oneline | grep -E '^[a-f0-9]+ (feat|fix|docs|chore|refactor|test):'

Challenge 2: ๐ŸŸก The Branch Weaver (๐Ÿ• 30 minutes)

Objective: Simulate a feature-branch workflow with parallel development and a merge conflict.

Acceptance Criteria:

Expected Branch Topology:

gitGraph
    commit id: "initial commit"
    commit id: "add index.html"
    branch feature/header
    checkout feature/header
    commit id: "add header"
    checkout main
    branch feature/footer
    checkout feature/footer
    commit id: "add footer"
    checkout main
    merge feature/header id: "merge header"
    merge feature/footer id: "merge footer (conflict resolved)"

Verification Command:

# Should show merge commits
git log --oneline --graph --all

# Verify no conflict markers remain
grep -rn '<<<<<<' . && echo 'FAIL: unresolved conflicts' || echo 'PASS: no conflicts'

Challenge 3: ๐Ÿ”ด The Remote Ranger (๐Ÿ• 25 minutes)

Objective: Practice the full local-to-remote workflow including forking and pull requests.

Acceptance Criteria:

Verification Command:

# Verify remote points to YOUR fork
git remote -v | grep 'your-username'

# Verify feature branch exists on remote
git branch -r | grep 'feature/my-improvement'

โš”๏ธ Boss Battle: The Git Gauntlet

Youโ€™ve trained with individual spells. Now face the ultimate trial โ€” a multi-phase challenge that tests every skill from this quest in a single, connected scenario.

๐Ÿฐ The Scenario

Youโ€™re building a โ€œQuest Logโ€ web page โ€” a simple HTML file that tracks your IT-Journey progress. You must use every Git skill from this quest to build it correctly.

Phase 1: Foundation (Repository Setup)

# Create and initialize the project
mkdir quest-log && cd quest-log
git init

# Create the initial file
cat > index.html << 'EOF'
<!DOCTYPE html>
<html>
<head><title>Quest Log</title></head>
<body>
  <h1>My Quest Log</h1>
  <ul>
    <li>Terminal Fundamentals โ€” โœ… Complete</li>
  </ul>
</body>
</html>
EOF

# Create .gitignore
echo -e ".DS_Store\n*.log\n.env" > .gitignore

git add .
git commit -m "feat: initialize quest log project"

Phase 2: Feature Development (Branching)

# Branch 1: Add styling
git switch -c feature/styling
cat > style.css << 'EOF'
body { font-family: sans-serif; max-width: 600px; margin: 2rem auto; }
h1 { color: #2d3748; }
li { padding: 0.5rem 0; }
EOF
# Link the stylesheet in index.html (add <link> in <head>)
git add .
git commit -m "feat: add basic CSS styling"
git switch main

# Branch 2: Add more quests (this will conflict with branch 1 in index.html)
git switch -c feature/more-quests
# Add Git Basics quest to the list in index.html
git add .
git commit -m "feat: add git basics quest to log"
git switch main

Phase 3: Integration (Merging + Conflict Resolution)

# Merge styling first
git merge feature/styling

# Merge more-quests (expect conflict in index.html)
git merge feature/more-quests
# >> RESOLVE THE CONFLICT <<
git add index.html
git commit -m "fix: resolve merge conflict in quest list"

Phase 4: Time Travel (Undo Operations)

# Make a deliberate mistake
echo "BROKEN CONTENT" >> index.html
git add . && git commit -m "feat: this is a mistake"

# Revert it safely
git revert HEAD --no-edit

# Verify the bad content is gone
cat index.html

Phase 5: Deployment (Push to Remote)

# Create the repo on GitHub, then:
git remote add origin https://github.com/yourusername/quest-log.git
git push -u origin main

๐Ÿ† Boss Battle Victory Conditions

Full Verification Script:

#!/bin/bash
echo "=== ๐Ÿฐ Git Gauntlet Verification ==="

# Check commit count
COMMITS=$(git log --oneline | wc -l | tr -d ' ')
[[ $COMMITS -ge 6 ]] && echo "โœ… Commits: $COMMITS (โ‰ฅ6)" || echo "โŒ Commits: $COMMITS (need โ‰ฅ6)"

# Check for merge commits
MERGES=$(git log --merges --oneline | wc -l | tr -d ' ')
[[ $MERGES -ge 1 ]] && echo "โœ… Merge commits found: $MERGES" || echo "โŒ No merge commits"

# Check for revert commits
REVERTS=$(git log --oneline | grep -c 'Revert\|revert')
[[ $REVERTS -ge 1 ]] && echo "โœ… Revert commits found: $REVERTS" || echo "โŒ No revert commits"

# Check for conflict markers
grep -rn '<<<<<<' . --include='*.html' --include='*.css' 2>/dev/null
[[ $? -ne 0 ]] && echo "โœ… No unresolved conflicts" || echo "โŒ Unresolved conflicts found!"

# Check .gitignore
[[ -f .gitignore ]] && echo "โœ… .gitignore exists" || echo "โŒ Missing .gitignore"

# Check remote
git remote -v | grep -q 'origin' && echo "โœ… Remote configured" || echo "โŒ No remote configured"

echo "=== Verification Complete ==="

๐Ÿ—บ๏ธ Complete Quest Flow

flowchart TD
    START["๐Ÿฐ Quest Start"] --> CH1["๐Ÿง™โ€โ™‚๏ธ Ch1: First Repository"]
    CH1 --> CP1{"โœ… Checkpoint 1\nRepo + Commits?"}
    CP1 -->|Pass| CH2["๐Ÿง™โ€โ™‚๏ธ Ch2: Branching"]
    CP1 -->|Fail| CH1
    CH2 --> CP2{"โœ… Checkpoint 2\nBranch + Merge?"}
    CP2 -->|Pass| CH3["๐Ÿง™โ€โ™‚๏ธ Ch3: Remotes"]
    CP2 -->|Fail| CH2
    CH3 --> CP3{"โœ… Checkpoint 3\nPush + Pull?"}
    CP3 -->|Pass| CH4["๐Ÿง™โ€โ™‚๏ธ Ch4: Undo Mistakes"]
    CP3 -->|Fail| CH3
    CH4 --> CHALLENGES["๐ŸŽฎ Implementation Challenges"]
    CHALLENGES --> BOSS{"โš”๏ธ Boss Battle:\nThe Git Gauntlet"}
    BOSS -->|Victory| REWARDS["๐ŸŽ Quest Rewards"]
    BOSS -->|Defeat| CHALLENGES
    REWARDS --> NEXT["๐Ÿ”ฎ Next Adventures"]
    
    style START fill:#6c5ce7,color:#fff
    style BOSS fill:#e17055,color:#fff,stroke-width:3px
    style REWARDS fill:#00b894,color:#fff
    style NEXT fill:#0984e3,color:#fff

๐Ÿ† Quest Completion Validation

Portfolio Artifacts Created

Skills Demonstrated

๐Ÿง  Final Knowledge Assessment

Before claiming your reward, you should be able to answer:

  1. Explain the three areas (working directory, staging area, repository) in your own words.
  2. Describe when you would use git revert vs. git reset.
  3. Draw (mentally or on paper) the branch topology for a feature-branch workflow.
  4. Troubleshoot a scenario where git push is rejected because the remote has new commits.

๐ŸŽ Quest Rewards and Achievements

๐Ÿ† Achievement Badges Earned

โšก Skills and Abilities Unlocked

๐Ÿ“ˆ Your Journey Progress


๐Ÿ”ฎ Your Next Epic Adventures

๐ŸŒ Skill Web Connections


๐Ÿ“š References & Resources

๐Ÿ“– Essential Documentation

๐ŸŽฎ Interactive Learning

๐Ÿ“‹ Quick References