use switch instead of checkout for branches

This commit is contained in:
Bjarke Sporring
2026-01-07 21:37:21 +01:00
parent 6b0e84934a
commit 7fb84560f5
2 changed files with 7 additions and 7 deletions

View File

@@ -43,12 +43,12 @@ Your goal is to create a feature branch, make commits on it, and understand how
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` and notice that `login.py` doesn't exist on 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` again and see that `login.py` is back!
10. Run `ls` (or check your file explorer) again and see that `login.py` is back!
> **Important Notes:**
> - Use `git switch` to change branches (modern Git command)
> - Use `git switch` to change branches
> - `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

View File

@@ -40,7 +40,7 @@ if ($branchExists) {
Write-Host "[PASS] Branch 'feature-login' exists" -ForegroundColor Green
} else {
Write-Host "[FAIL] Branch 'feature-login' not found" -ForegroundColor Red
Write-Host "[HINT] Create the branch with: git checkout -b feature-login" -ForegroundColor Yellow
Write-Host "[HINT] Create the branch with: git switch -c feature-login" -ForegroundColor Yellow
$allChecksPassed = $false
Set-Location ..
exit 1
@@ -67,7 +67,7 @@ if (Test-Path "login.py") {
}
# Switch to main and verify login.py doesn't exist
git checkout main 2>$null | Out-Null
git switch main 2>$null | Out-Null
if (-not (Test-Path "login.py")) {
Write-Host "[PASS] File 'login.py' does NOT exist in main branch (branches are independent!)" -ForegroundColor Green
} else {
@@ -78,7 +78,7 @@ if (-not (Test-Path "login.py")) {
# Switch back to original branch
if ($originalBranch) {
git checkout $originalBranch 2>$null | Out-Null
git switch $originalBranch 2>$null | Out-Null
}
Set-Location ..
@@ -91,7 +91,7 @@ if ($allChecksPassed) {
Write-Host "=====================================" -ForegroundColor Green
Write-Host "`nYou've successfully learned about Git branches!" -ForegroundColor Cyan
Write-Host "You now understand:" -ForegroundColor Cyan
Write-Host " - How to create branches with git checkout -b" -ForegroundColor White
Write-Host " - How to create branches with git switch -c" -ForegroundColor White
Write-Host " - How to switch between branches" -ForegroundColor White
Write-Host " - That branches are independent lines of development" -ForegroundColor White
Write-Host " - That files in one branch don't affect another" -ForegroundColor White