> ## 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

![Git Distributed Version Control](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)

# 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:

> **Distributed**
>
> Every developer has the full history. No single point of failure. Work offline.

> **Fast**
>
> Branching and merging are instant. Designed for the Linux kernel (millions of lines).

> **Industry Standard**
>
> GitHub, GitLab, Bitbucket—all built on Git. 97% of developers use it.

> **Powerful**
>
> Branching strategies, rebasing, cherry-picking—handle any workflow.

***

## 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

**1. Fundamentals**

Repositories, commits, the staging area. The mental model that makes everything else click.
[Start Here](https://resources.devweekends.com/courses/devops-tools/git-fundamentals.md)

**2. Branching and Merging**

Create branches in milliseconds, merge with confidence, resolve conflicts like a pro.
[Learn Branching](https://resources.devweekends.com/courses/devops-tools/git-branching.md)

**3. Collaboration**

Remote repositories, push/pull workflows, pull requests, code review. Working with teams.
[Collaborate](https://resources.devweekends.com/courses/devops-tools/git-collaboration.md)

**4. Advanced Topics**

Rebase vs merge (the eternal debate), interactive rebase, cherry-pick, stash. Power user territory.
[Go Advanced](https://resources.devweekends.com/courses/devops-tools/git-advanced.md)

**5. 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](https://resources.devweekends.com/courses/devops-tools/git-internals)

**6. Git Hooks**

Automate workflows, enforce standards, integrate with CI/CD. Git as a platform.
[Learn Hooks](https://resources.devweekends.com/courses/devops-tools/git-hooks.md)

***

## 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

![Git Workflow](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)

### 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

> **Branching is Cheap**
>
> 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
> ```

> **Complete History**
>
> 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
> ```

> **Collaboration**
>
> Multiple developers, same codebase, no conflicts (mostly). Pull requests for code review.
>
> ```bash theme={null}
> git pull origin main
> git push origin feature-x
> ```

> **Safety**
>
> 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
> ```

***

## Real-World Use Cases

> **Solo Projects**
>
> Track changes, experiment with branches, never lose work

> **Team Development**
>
> Parallel feature development, code review, merge strategies

> **Open Source**
>
> Fork projects, submit pull requests, contribute to Linux, React, etc.

> **DevOps/CI/CD**
>
> Trigger builds on push, deploy from branches, GitOps workflows

***

## Prerequisites

> [!NOTE]
>
> **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
> ```

***

## 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

**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
```

**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
```

**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
```

***

## 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.

> [!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

***

## 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

**1. Week 1: Basics**

Install Git, learn init/add/commit/log, practice daily commits

**2. Week 2: Branching**

Create branches, merge changes, resolve conflicts

**3. Week 3: Collaboration**

Use GitHub/GitLab, fork repos, create pull requests

**4. Week 4: Advanced**

Master rebase, cherry-pick, understand Git internals

***

## 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](https://resources.devweekends.com/courses/devops-tools/git-fundamentals.md) or jump to [Internals Deep Dive](https://resources.devweekends.com/courses/devops-tools/git-internals) if you want to understand how Git really works.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.