4.4 KiB
Module 01: Git Basics
Learning Objectives
- Understand what a git repository is
- Learn the basic git workflow: modify → stage → commit
- Use
git statusto check repository state - Use
git addto stage changes - Use
git committo save changes
Challenge
In this challenge, you'll learn the fundamental git workflow.
Setup
Run the setup script to prepare the challenge:
.\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:
- Navigate into the
challengedirectory:cd challenge - Initialize a new git repository:
git init(this is your first step!) - Check the status of your repository:
git status - Stage the file you want to commit:
git add welcome.txt(orgit add .to stage all files) - Check the status again and see the difference
git status. Notice the file is now staged and ready to be committed. - Create a commit:
git commit -m "add welcome.txt" - Check the status again and see the difference
git status. Notice the file no longer appears in the output. - Stage the next file:
git add instructions.txt(orgit add .to stage all files) - Check the status again and see the difference
git status. Notice the file is now staged and ready to be committed. - Create a commit:
git commit -m "add instructions.txt" - Check the status again and see the difference
git status. Notice that the files are now not shown in status. If and when you change something about the file you will once again see it in thegit statuscommand.
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 (use
git add .to add all files in the folder) - 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: A preparation area for your next commit, you first add the files to the stage, and then you commit the files to repository.
- Commit: A snapshot of your staged changes
Useful Commands
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.
# 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:
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:
.\reset.ps1
This will remove your challenge directory and set up a new one.