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

@@ -117,24 +117,19 @@ git branch -D <branch-name>
Force delete a branch (even if not merged).
```bash
git checkout <branch-name>
git switch <branch-name>
```
Switch to a different branch.
```bash
git checkout -b <branch-name>
git switch -c <branch-name>
```
Create a new branch and switch to it in one command.
```bash
git switch <branch-name>
git switch -
```
Modern command to switch branches (alternative to checkout).
```bash
git switch -c <branch-name>
```
Create a new branch and switch to it (alternative to checkout -b).
Switch back to the previous branch.
### Merging
@@ -162,6 +157,23 @@ git commit
```
Stage resolved files and complete the merge.
### Restoring Files
```bash
git restore <file>
```
Discard changes in working directory (restore from last commit).
```bash
git restore --staged <file>
```
Unstage a file (remove from staging area but keep changes).
```bash
git restore --source=<commit> <file>
```
Restore a file to its state in a specific commit.
---
## Advanced
@@ -420,7 +432,8 @@ Automatically test commits using a script to find the bad commit.
### Undoing Changes
- **Haven't committed yet?** Use `git checkout -- <file>` or `git restore <file>` to discard changes
- **Haven't committed yet?** Use `git restore <file>` to discard changes
- **Staged but want to unstage?** Use `git restore --staged <file>`
- **Committed to wrong branch?** Use `git cherry-pick` to copy the commit to the right branch
- **Want to change last commit message?** Use `git commit --amend`
- **Pushed to remote already?** Use `git revert` (not reset) to safely undo
@@ -459,7 +472,7 @@ Each workshop module focuses on specific commands:
- **Module 01**: init, add, commit, status
- **Module 02**: log, show, diff
- **Module 03**: branch, checkout/switch
- **Module 03**: branch, switch
- **Module 04**: merge (fast-forward and three-way)
- **Module 05**: merge (conflict resolution)
- **Module 06**: rebase