Files
2026-01-07 19:26:11 +01:00

112 lines
3.6 KiB
Markdown

# 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
Your goal is to commit both `welcome.txt` and `instructions.txt` to a git repository. Here's a suggested approach:
1. Navigate into the `challenge` directory: `cd challenge`
2. **Initialize a new git repository**: `git init` (this is your first step!)
3. Check the status of your repository: `git status`
4. Stage the files you want to commit: `git add welcome.txt` (or `git add .` to stage all files)
5. Create a commit: `git commit -m "Your commit message"`
6. Verify both files are committed: `git ls-tree -r HEAD --name-only`
**Important Notes**:
- The challenge directory is NOT a git repository until you run `git init`. This is intentional - you're learning to start from scratch!
- You can commit both files together in one commit, or separately in multiple commits - it's up to you!
- The verification script checks that both files are committed, not the specific commit messages or order
### 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 <file> # Stage a specific file for commit
git add . # Stage all files in current directory
git commit -m "<message>" # Create a commit with a message
git ls-tree -r HEAD --name-only # ADVANCED: List all files in the latest commit
git log # View commit history
```
### Verification
Once you think you've completed the challenge, run the verification script.
**Important:** Run this from the **module directory**, not the challenge directory.
```powershell
# If you're in the challenge directory, go back up:
cd ..
# Then verify:
.\verify.ps1
```
This will check if you've successfully completed all the steps.
### Troubleshooting
**Error: "fatal: unable to auto-detect email address"**
This means Git doesn't know who you are yet. You need to configure your name and email:
```powershell
git config user.name "Your Name"
git config user.email "your.email@example.com"
```
Then try your commit again. For more details, see the "Requirements" section in the main README.md.
**Error: "Not a git repository"**
Make sure you ran `git init` in the challenge directory. This creates a hidden `.git` folder that tracks your project.
**Can't find the challenge directory?**
Make sure you ran `.\setup.ps1` first from the module directory. This creates the `challenge/` folder.
**Where am I?**
Use `pwd` (Print Working Directory) to see your current location:
- If you're in something like `.../module-01-basics/challenge`, you're in the challenge directory
- If you're in something like `.../module-01-basics`, you're in the module directory
### Need to Start Over?
If you want to reset the challenge and start fresh, run:
```powershell
.\reset.ps1
```
This will remove your challenge directory and set up a new one.