# 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 switch -c` - Switch between branches using `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 switch -c 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 switch main` 8. Run `ls` (or check your file explorer) and notice that `login.py` doesn't exist on main! 9. Switch back to feature-login: `git switch feature-login` 10. Run `ls` (or check your file explorer) again and see that `login.py` is back! > **Important Notes:** > - Use `git switch` to change branches > - `git switch -c ` creates and switches in one command > - 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 # Create a new branch git switch # Switch to an existing branch git switch -c # Create and switch to new branch git switch - # Switch back to previous branch git branch -d # 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.