commit 3a7f682cc29fa4421173301a2da26f2adb084ba3 Author: Bjarke Sporring Date: Fri Dec 19 11:18:25 2025 +0100 feat: add module 1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc4ed91 --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +# Git Workshop + +A hands-on, progressive git workshop with practical challenges ranging from basic to advanced concepts. + +## Workshop Structure + +Each module is a self-contained challenge that teaches specific git concepts: + +- **Module 01**: Git Basics (init, add, commit, status) +- **Module 02**: Understanding the Staging Area +- **Module 03**: Viewing History (log, diff) +- **Module 04**: Branching Basics +- **Module 05**: Merging +- **Module 06**: Merge Conflicts +- **Module 07**: Rebasing +- **Module 08**: Interactive Rebase +- **Module 09**: Cherry-pick +- **Module 10**: Reset vs Revert +- **Module 11**: Stash +- **Module 12**: Working with Remotes + +## How to Use This Workshop + +1. Navigate to a module directory (e.g., `module-01-basics`) +2. Read the `README.md` to understand the challenge +3. Run `./setup.ps1` to create the challenge environment +4. Complete the challenge using git commands +5. Run `./verify.ps1` to check if you've solved it correctly +6. Move to the next module + +## Requirements + +- Git installed and configured +- PowerShell (Windows PowerShell 5.1+ or PowerShell Core 7+) +- Basic command line knowledge + +## Getting Started + +Start with Module 01: + +```powershell +cd module-01-basics +.\setup.ps1 +``` + +Follow the instructions in each module's README.md file. diff --git a/module-01-basics/README.md b/module-01-basics/README.md new file mode 100644 index 0000000..e7bb798 --- /dev/null +++ b/module-01-basics/README.md @@ -0,0 +1,59 @@ +# Module 01: Git Basics + +## Learning Objectives + +- Understand what a git repository is +- Learn the basic git workflow: modify → stage → commit +- Use `git status` to check repository state +- Use `git add` to stage changes +- Use `git commit` to save changes + +## Challenge + +In this challenge, you'll learn the fundamental git workflow. + +### Setup + +Run the setup script to prepare the challenge: + +```powershell +.\setup.ps1 +``` + +This will create a directory called `challenge` with some files that need to be committed. + +### Your Task + +1. Navigate into the `challenge` directory +2. Initialize a new git repository +3. Check the status of your repository +4. Stage the file `welcome.txt` +5. Create a commit with the message "Add welcome file" +6. Stage the file `instructions.txt` +7. Create a commit with the message "Add instructions" + +### Key Concepts + +- **Repository**: A directory tracked by git, containing your project files and their history +- **Working Directory**: The files you see and edit +- **Staging Area (Index)**: A preparation area for your next commit +- **Commit**: A snapshot of your staged changes + +### Useful Commands + +```bash +git init # Initialize a new git repository +git status # Show the working tree status +git add # Stage a file for commit +git commit -m "" # Create a commit with a message +``` + +### Verification + +Once you think you've completed the challenge, run: + +```powershell +.\verify.ps1 +``` + +This will check if you've successfully completed all the steps. diff --git a/module-01-basics/challenge/instructions.txt b/module-01-basics/challenge/instructions.txt new file mode 100644 index 0000000..5118096 --- /dev/null +++ b/module-01-basics/challenge/instructions.txt @@ -0,0 +1,11 @@ +Git Basics Instructions +======================== + +The basic git workflow follows these steps: + +1. Make changes to files in your working directory +2. Stage the changes you want to commit (git add) +3. Commit the staged changes with a message (git commit) + +This workflow allows you to carefully select which changes +to include in each commit, making your history clean and meaningful. diff --git a/module-01-basics/challenge/welcome.txt b/module-01-basics/challenge/welcome.txt new file mode 100644 index 0000000..0ddf97a --- /dev/null +++ b/module-01-basics/challenge/welcome.txt @@ -0,0 +1,8 @@ +Welcome to Git Workshop! + +This is your first challenge. You'll learn the basics of git: +- Initializing a repository +- Staging changes +- Creating commits + +Good luck! diff --git a/module-01-basics/setup.ps1 b/module-01-basics/setup.ps1 new file mode 100644 index 0000000..9d1d4f8 --- /dev/null +++ b/module-01-basics/setup.ps1 @@ -0,0 +1,64 @@ +#!/usr/bin/env pwsh + +<# +.SYNOPSIS + Sets up the Module 01 challenge environment. + +.DESCRIPTION + Creates a challenge directory with files that need to be committed to git. + The student will need to initialize the repository and make commits. +#> + +Write-Host "Setting up Module 01: Git Basics Challenge..." -ForegroundColor Cyan +Write-Host "" + +# Remove existing challenge directory if it exists +if (Test-Path "challenge") { + Write-Host "Removing existing challenge directory..." -ForegroundColor Yellow + Remove-Item -Path "challenge" -Recurse -Force +} + +# Create challenge directory +Write-Host "Creating challenge directory..." -ForegroundColor Green +New-Item -ItemType Directory -Path "challenge" | Out-Null + +# Create welcome.txt +$welcomeContent = @" +Welcome to Git Workshop! + +This is your first challenge. You'll learn the basics of git: +- Initializing a repository +- Staging changes +- Creating commits + +Good luck! +"@ + +Set-Content -Path "challenge/welcome.txt" -Value $welcomeContent + +# Create instructions.txt +$instructionsContent = @" +Git Basics Instructions +======================== + +The basic git workflow follows these steps: + +1. Make changes to files in your working directory +2. Stage the changes you want to commit (git add) +3. Commit the staged changes with a message (git commit) + +This workflow allows you to carefully select which changes +to include in each commit, making your history clean and meaningful. +"@ + +Set-Content -Path "challenge/instructions.txt" -Value $instructionsContent + +Write-Host "" +Write-Host "Setup complete!" -ForegroundColor Green +Write-Host "" +Write-Host "Next steps:" -ForegroundColor Cyan +Write-Host " 1. cd challenge" +Write-Host " 2. Read the README.md in the parent directory" +Write-Host " 3. Complete the challenge" +Write-Host " 4. Run ../verify.ps1 to check your solution" +Write-Host "" diff --git a/module-01-basics/verify.ps1 b/module-01-basics/verify.ps1 new file mode 100644 index 0000000..155bab7 --- /dev/null +++ b/module-01-basics/verify.ps1 @@ -0,0 +1,110 @@ +#!/usr/bin/env pwsh + +<# +.SYNOPSIS + Verifies the Module 01 challenge solution. + +.DESCRIPTION + Checks if the student has correctly: + - Initialized a git repository + - Created two commits with the correct messages + - Committed the correct files +#> + +Write-Host "Verifying Module 01: Git Basics Challenge..." -ForegroundColor Cyan +Write-Host "" + +$allChecksPassed = $true + +# Check if challenge directory exists +if (-not (Test-Path "challenge")) { + Write-Host "[FAIL] Challenge directory not found. Run setup.ps1 first." -ForegroundColor Red + exit 1 +} + +Set-Location "challenge" + +# Check if git repository exists +if (-not (Test-Path ".git")) { + Write-Host "[FAIL] No git repository found. Did you run 'git init'?" -ForegroundColor Red + Set-Location ".." + exit 1 +} + +Write-Host "[PASS] Git repository initialized" -ForegroundColor Green + +# Check number of commits +$commitCount = (git rev-list --all --count 2>$null) +if ($commitCount -ne 2) { + Write-Host "[FAIL] Expected 2 commits, found $commitCount" -ForegroundColor Red + $allChecksPassed = $false +} else { + Write-Host "[PASS] Correct number of commits (2)" -ForegroundColor Green +} + +# Get commit messages (newest first) +$commits = git log --pretty=format:"%s" --reverse 2>$null + +if ($commits) { + $commitArray = $commits -split "`n" + + # Check first commit + if ($commitArray.Count -ge 1) { + if ($commitArray[0] -eq "Add welcome file") { + Write-Host "[PASS] First commit message correct" -ForegroundColor Green + } else { + Write-Host "[FAIL] First commit message incorrect. Expected 'Add welcome file', got '$($commitArray[0])'" -ForegroundColor Red + $allChecksPassed = $false + } + + # Check files in first commit + $filesInFirstCommit = git diff-tree --no-commit-id --name-only -r HEAD~1 2>$null + if ($filesInFirstCommit -match "welcome.txt") { + Write-Host "[PASS] First commit contains welcome.txt" -ForegroundColor Green + } else { + Write-Host "[FAIL] First commit should contain welcome.txt" -ForegroundColor Red + $allChecksPassed = $false + } + } + + # Check second commit + if ($commitArray.Count -ge 2) { + if ($commitArray[1] -eq "Add instructions") { + Write-Host "[PASS] Second commit message correct" -ForegroundColor Green + } else { + Write-Host "[FAIL] Second commit message incorrect. Expected 'Add instructions', got '$($commitArray[1])'" -ForegroundColor Red + $allChecksPassed = $false + } + + # Check files in second commit + $filesInSecondCommit = git diff-tree --no-commit-id --name-only -r HEAD 2>$null + if ($filesInSecondCommit -match "instructions.txt") { + Write-Host "[PASS] Second commit contains instructions.txt" -ForegroundColor Green + } else { + Write-Host "[FAIL] Second commit should contain instructions.txt" -ForegroundColor Red + $allChecksPassed = $false + } + } +} + +Set-Location ".." + +Write-Host "" +if ($allChecksPassed) { + Write-Host "========================================" -ForegroundColor Green + Write-Host " CONGRATULATIONS! Challenge Complete! " -ForegroundColor Green + Write-Host "========================================" -ForegroundColor Green + Write-Host "" + Write-Host "You've mastered the basics of git!" -ForegroundColor Cyan + Write-Host "You can now move on to Module 02." -ForegroundColor Cyan + Write-Host "" +} else { + Write-Host "========================================" -ForegroundColor Red + Write-Host " Challenge Not Complete - Try Again! " -ForegroundColor Red + Write-Host "========================================" -ForegroundColor Red + Write-Host "" + Write-Host "Review the errors above and try again." -ForegroundColor Yellow + Write-Host "Hint: Check 'git log' and 'git status' to see what you've done." -ForegroundColor Yellow + Write-Host "" + exit 1 +}