feat: use switch instead of checkout

This commit is contained in:
Bjarke Sporring
2026-01-05 12:38:35 +01:00
parent a7b511c8cb
commit e29b9bca70
8 changed files with 55 additions and 44 deletions

View File

@@ -4,8 +4,8 @@
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`
- 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
@@ -38,19 +38,18 @@ Your goal is to create a feature branch, make commits on it, and understand how
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`
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 checkout main`
7. Switch back to main: `git switch main`
8. Run `ls` and notice that `login.py` doesn't exist on main!
9. Switch back to feature-login: `git checkout feature-login`
9. Switch back to feature-login: `git switch 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
> - Use `git switch` to change branches (modern Git command)
> - `git switch -c <name>` 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
@@ -66,10 +65,9 @@ Your goal is to create a feature branch, make commits on it, and understand how
```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 switch <branch> # Switch to an existing branch
git switch -c <name> # Create and switch to new branch
git switch - # Switch back to previous branch
git branch -d <name> # Delete a branch (we won't use this yet)
```