feat: initial module 3
This commit is contained in:
94
module-03-branching/README.md
Normal file
94
module-03-branching/README.md
Normal file
@@ -0,0 +1,94 @@
|
||||
# Module 03: Branching Basics
|
||||
|
||||
## Learning Objectives
|
||||
|
||||
In this module, you will:
|
||||
- Understand what a branch is in Git
|
||||
- Create new branches using `git branch` or `git checkout -b`
|
||||
- Switch between branches using `git checkout` or `git switch`
|
||||
- View all branches with `git branch`
|
||||
- Understand that branches allow parallel development
|
||||
|
||||
## Challenge
|
||||
|
||||
### Setup
|
||||
|
||||
Run the setup script to create your challenge environment:
|
||||
|
||||
```powershell
|
||||
.\setup.ps1
|
||||
```
|
||||
|
||||
This will create a `challenge/` directory with a Git repository that has some initial commits on the main branch.
|
||||
|
||||
### Your Task
|
||||
|
||||
Your goal is to create a feature branch, make commits on it, and understand how branches work independently.
|
||||
|
||||
**Steps:**
|
||||
|
||||
1. Create a new branch called `feature-login`
|
||||
2. Switch to the new branch
|
||||
3. Create a new file `login.py` with some login functionality
|
||||
4. Commit the new file to your feature branch
|
||||
5. Make another change to `login.py` and commit it
|
||||
6. Switch back to the main branch and observe that `login.py` doesn't exist there
|
||||
|
||||
**Suggested Approach:**
|
||||
|
||||
1. Navigate to the challenge directory: `cd challenge`
|
||||
2. View existing branches: `git branch`
|
||||
3. Create and switch to new branch: `git checkout -b feature-login`
|
||||
4. Create `login.py` with any content you like
|
||||
5. Stage and commit: `git add login.py` and `git commit -m "Add login functionality"`
|
||||
6. Modify `login.py`, then commit again
|
||||
7. Switch back to main: `git checkout main`
|
||||
8. Run `ls` and notice that `login.py` doesn't exist on main!
|
||||
9. Switch back to feature-login: `git checkout feature-login`
|
||||
10. Run `ls` again and see that `login.py` is back!
|
||||
|
||||
> **Important Notes:**
|
||||
> - You can use either `git checkout` or `git switch` to change branches
|
||||
> - `git checkout -b <name>` creates and switches in one command
|
||||
> - `git switch -c <name>` is the newer equivalent
|
||||
> - Branches are independent - files in one branch don't affect another until you merge
|
||||
> - You can switch between branches as many times as you want
|
||||
|
||||
## Key Concepts
|
||||
|
||||
- **Branch**: A lightweight movable pointer to a commit. Branches allow you to work on different features independently.
|
||||
- **HEAD**: A pointer to the current branch you're working on. When you switch branches, HEAD moves.
|
||||
- **main/master**: The default branch name in Git (main is the modern convention, master is older).
|
||||
- **Feature Branch**: A branch created to develop a specific feature, separate from the main codebase.
|
||||
|
||||
## Useful Commands
|
||||
|
||||
```bash
|
||||
git branch # List all branches (* shows current)
|
||||
git branch <name> # Create a new branch
|
||||
git checkout <branch> # Switch to an existing branch
|
||||
git checkout -b <name> # Create and switch to new branch
|
||||
git switch <branch> # Switch to a branch (newer syntax)
|
||||
git switch -c <name> # Create and switch (newer syntax)
|
||||
git branch -d <name> # Delete a branch (we won't use this yet)
|
||||
```
|
||||
|
||||
## Verification
|
||||
|
||||
Once you've completed the challenge, verify your solution:
|
||||
|
||||
```powershell
|
||||
.\verify.ps1
|
||||
```
|
||||
|
||||
The verification script will check that you've created the branch, made commits, and that the branches are independent.
|
||||
|
||||
## Need to Start Over?
|
||||
|
||||
If you want to reset the challenge and start fresh:
|
||||
|
||||
```powershell
|
||||
.\reset.ps1
|
||||
```
|
||||
|
||||
This will remove the challenge directory and run the setup script again, giving you a clean slate.
|
||||
Reference in New Issue
Block a user