> ## Documentation Index
> Fetch the complete documentation index at: https://resources.devweekends.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Git Crash Course

> Master distributed version control - the skill every developer needs

<Frame>
  <img src="https://mintcdn.com/devweeekends/emzPt-9B_R8UKdqm/images/courses/devops-tools/git-distributed.svg?fit=max&auto=format&n=emzPt-9B_R8UKdqm&q=85&s=693ae06ed73ae6da30e21df2e7726b75" alt="Git Distributed Version Control" width="1080" height="1080" data-path="images/courses/devops-tools/git-distributed.svg" />
</Frame>

# Git Crash Course

> **"I'm an egotistical bastard, and I name all my projects after myself. First Linux, now Git."** - Linus Torvalds

Git is not just a tool. It is the foundation of modern software development. Every professional developer uses it. Every open source project depends on it. Every company you will ever work for expects you to know it. This course takes you from git-curious to git-confident.

***

## Why Git Matters

Every professional developer uses version control. Here's why Git won:

<CardGroup cols={2}>
  <Card title="Distributed" icon="network-wired">
    Every developer has the full history. No single point of failure. Work offline.
  </Card>

  <Card title="Fast" icon="bolt">
    Branching and merging are instant. Designed for the Linux kernel (millions of lines).
  </Card>

  <Card title="Industry Standard" icon="building">
    GitHub, GitLab, Bitbucket—all built on Git. 97% of developers use it.
  </Card>

  <Card title="Powerful" icon="wand-magic-sparkles">
    Branching strategies, rebasing, cherry-picking—handle any workflow.
  </Card>
</CardGroup>

***

## The Story Behind Git

**2005**: Linus Torvalds needed a version control system for Linux kernel development. The existing tool (BitKeeper) became proprietary.

**The Solution**: Linus built Git in just **10 days**. His goals:

* Speed (handle Linux kernel scale)
* Distributed (no central server dependency)
* Data integrity (cryptographic hashing)
* Non-linear development (branching)

**Today**: Git powers:

* 100+ million repositories on GitHub
* Every major open source project
* Companies from startups to Google, Microsoft, Facebook

***

## What You'll Learn

<Steps>
  <Step title="Fundamentals">
    Repositories, commits, the staging area. The mental model that makes everything else click.
    [Start Here](/courses/devops-tools/git-fundamentals)
  </Step>

  <Step title="Branching and Merging">
    Create branches in milliseconds, merge with confidence, resolve conflicts like a pro.
    [Learn Branching](/courses/devops-tools/git-branching)
  </Step>

  <Step title="Collaboration">
    Remote repositories, push/pull workflows, pull requests, code review. Working with teams.
    [Collaborate](/courses/devops-tools/git-collaboration)
  </Step>

  <Step title="Advanced Topics">
    Rebase vs merge (the eternal debate), interactive rebase, cherry-pick, stash. Power user territory.
    [Go Advanced](/courses/devops-tools/git-advanced)
  </Step>

  <Step title="Internals Deep Dive">
    The object model, SHA-1 hashing, packfiles, refs. If you love understanding how things actually work, this one is for you.
    [Explore Internals](/courses/devops-tools/git-internals)
  </Step>

  <Step title="Git Hooks">
    Automate workflows, enforce standards, integrate with CI/CD. Git as a platform.
    [Learn Hooks](/courses/devops-tools/git-hooks)
  </Step>
</Steps>

***

## Git vs Other Version Control Systems

| Feature            | Git                | SVN             | Mercurial          |
| ------------------ | ------------------ | --------------- | ------------------ |
| **Architecture**   | Distributed        | Centralized     | Distributed        |
| **Speed**          | Very Fast          | Slow            | Fast               |
| **Branching**      | Instant, cheap     | Slow, expensive | Fast               |
| **Offline Work**   | Full functionality | Limited         | Full functionality |
| **Market Share**   | \~97%              | \~2%            | \~1%               |
| **Learning Curve** | Moderate           | Easy            | Easy               |

**Why Git Won**: Speed + distributed model + GitHub's network effect.

***

## Core Concepts Preview

<img src="https://mintcdn.com/devweeekends/emzPt-9B_R8UKdqm/images/courses/devops-tools/git-workflow.svg?fit=max&auto=format&n=emzPt-9B_R8UKdqm&q=85&s=73bbc32719156c1b5c2700cd3c37d0c0" alt="Git Workflow" width="1080" height="1080" data-path="images/courses/devops-tools/git-workflow.svg" />

### The Three States

Every file in Git is in one of three states:

1. **Modified**: Changed but not staged
2. **Staged**: Marked for next commit
3. **Committed**: Safely stored in repository

### The Three Areas

1. **Working Directory**: Your actual files
2. **Staging Area (Index)**: Prepared changes
3. **Repository (.git)**: Committed history

***

## Why Developers Love Git

<AccordionGroup>
  <Accordion title="Branching is Cheap" icon="code-branch">
    Create a branch in milliseconds. Experiment freely. Delete failed experiments.

    ```bash theme={null}
    git branch feature-x    # Create branch
    git checkout feature-x  # Switch to it
    # Or in one command:
    git checkout -b feature-x
    ```
  </Accordion>

  <Accordion title="Complete History" icon="clock-rotate-left">
    Every commit is a snapshot. Travel back in time. Find when bugs were introduced.

    ```bash theme={null}
    git log --oneline --graph --all
    git bisect  # Binary search for bugs
    ```
  </Accordion>

  <Accordion title="Collaboration" icon="users">
    Multiple developers, same codebase, no conflicts (mostly). Pull requests for code review.

    ```bash theme={null}
    git pull origin main
    git push origin feature-x
    ```
  </Accordion>

  <Accordion title="Safety" icon="shield">
    SHA-1 hashing ensures data integrity. Almost impossible to lose committed work.

    ```bash theme={null}
    git reflog  # See everything you've done
    git reset --hard HEAD@{1}  # Undo mistakes
    ```
  </Accordion>
</AccordionGroup>

***

## Real-World Use Cases

<CardGroup cols={2}>
  <Card title="Solo Projects" icon="user">
    Track changes, experiment with branches, never lose work
  </Card>

  <Card title="Team Development" icon="users">
    Parallel feature development, code review, merge strategies
  </Card>

  <Card title="Open Source" icon="code">
    Fork projects, submit pull requests, contribute to Linux, React, etc.
  </Card>

  <Card title="DevOps/CI/CD" icon="gears">
    Trigger builds on push, deploy from branches, GitOps workflows
  </Card>
</CardGroup>

***

## Prerequisites

<Info>
  **What You Need**:

  * Basic command line knowledge (cd, ls, mkdir)
  * A text editor (VS Code, Sublime, Vim)
  * Git installed on your system

  **Installation**:

  * **Windows**: Download from [git-scm.com](https://git-scm.com)
  * **macOS**: `brew install git` or Xcode Command Line Tools
  * **Linux**: `sudo apt install git` (Ubuntu) or `sudo yum install git` (RHEL)

  **Verify Installation**:

  ```bash theme={null}
  git --version
  # Should show: git version 2.x.x
  ```
</Info>

***

## Course Structure

This crash course is designed to take you from zero to productive in 8-10 hours.

### Module 1: Fundamentals (2-3 hours)

Git installation, configuration, the mental model. Creating repositories, staging changes, making commits. Understanding the three states and three areas.

### Module 2: Branching and Merging (2-3 hours)

Branch creation (it is instant, abuse this), switching contexts, merging strategies, conflict resolution. The workflows that make teams productive.

### Module 3: Collaboration (2-3 hours)

Remotes, cloning, fetching, pulling, pushing. Forking repos, creating pull requests, code review etiquette. GitHub/GitLab workflows.

### Module 4: Advanced Topics (2-3 hours)

The rebase vs merge debate (both have their place), interactive rebase for clean history, cherry-picking commits, stashing work in progress.

### Module 5: Internals Deep Dive (1-2 hours)

The object database, content-addressable storage, SHA-1 hashing, packfiles, refs. **If you love internals, continue. If not, you are still a competent Git user.**

### Module 6: Git Hooks (1 hour)

Pre-commit hooks, pre-push hooks, server-side hooks. Automate quality gates and integrate with CI/CD.

***

## Common Git Workflows

<Tabs>
  <Tab title="Feature Branch">
    ```bash theme={null}
    # Create feature branch
    git checkout -b feature/user-auth

    # Make changes, commit
    git add .
    git commit -m "Add user authentication"

    # Push to remote
    git push origin feature/user-auth

    # Create pull request on GitHub/GitLab
    # After review, merge to main
    ```
  </Tab>

  <Tab title="Gitflow">
    ```bash theme={null}
    # Main branches: main, develop
    # Supporting: feature/*, release/*, hotfix/*

    # Start feature
    git checkout -b feature/new-feature develop

    # Finish feature
    git checkout develop
    git merge --no-ff feature/new-feature
    git branch -d feature/new-feature
    ```
  </Tab>

  <Tab title="Trunk-Based">
    ```bash theme={null}
    # Everyone commits to main/trunk
    # Short-lived feature branches (< 1 day)

    git checkout -b quick-fix
    # Make changes
    git commit -m "Fix bug"
    git push origin quick-fix
    # Immediate merge after CI passes
    ```
  </Tab>
</Tabs>

***

## Git Best Practices

<Warning>
  **Commit Message Guidelines**:

  ```
  feat: add user authentication
  fix: resolve login timeout issue
  docs: update README with setup instructions
  refactor: simplify database query logic
  test: add unit tests for auth service
  ```

  Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification.
</Warning>

<Tip>
  **Commit Often, Push Regularly**:

  * Commit logical units of work
  * Write descriptive commit messages
  * Push at least daily to backup your work
  * Use branches for features, fixes, experiments
</Tip>

***

## What Makes Git Powerful

1. **Snapshots, Not Diffs**: Unlike SVN which stores diffs between versions, Git stores complete snapshots. This makes history traversal, branching, and comparisons extremely fast because Git never needs to "replay" a chain of diffs.
2. **Local Operations**: Almost everything (commits, branches, diffs, log, blame) happens on your local disk. No network round-trip to a central server. You can work on a plane.
3. **Integrity**: Every object is checksummed with SHA-1. If a single bit is corrupted in transit or on disk, Git detects it. This is why Git is the only version control system where you can trust that the code you checked out is exactly what was committed.
4. **Append-Only**: Git almost never deletes data. Even "destructive" operations like rebase create new commits -- the old ones remain accessible via reflog for 90 days. Committed work is nearly impossible to lose.
5. **Branching Model**: Branches are 41-byte pointer files, not directory copies. Creating a branch takes milliseconds regardless of repository size. This changes how you work -- branches become disposable experiments, not heavy commitments.

***

## Learning Path

<Steps>
  <Step title="Week 1: Basics">
    Install Git, learn init/add/commit/log, practice daily commits
  </Step>

  <Step title="Week 2: Branching">
    Create branches, merge changes, resolve conflicts
  </Step>

  <Step title="Week 3: Collaboration">
    Use GitHub/GitLab, fork repos, create pull requests
  </Step>

  <Step title="Week 4: Advanced">
    Master rebase, cherry-pick, understand Git internals
  </Step>
</Steps>

***

## Success Metrics

By the end of this crash course, you will be able to:

* Initialize repositories and make commits without thinking
* Create and merge branches with confidence
* Resolve merge conflicts (they are not as scary as they seem)
* Collaborate using GitHub/GitLab like you have done it for years
* Use advanced features like rebase, cherry-pick, and interactive staging
* Understand Git internals and troubleshoot when things go wrong
* Follow industry-standard workflows (GitFlow, trunk-based, feature branches)

***

Ready to master Git? Start with [Git Fundamentals](/courses/devops-tools/git-fundamentals) or jump to [Internals Deep Dive](/courses/devops-tools/git-internals) if you want to understand how Git really works.
