refactor: move 08 down a step
This commit is contained in:
395
01-essentials/08-multiplayer/03_TASKS.md
Normal file
395
01-essentials/08-multiplayer/03_TASKS.md
Normal file
@@ -0,0 +1,395 @@
|
||||
# Multiplayer Git Tasks
|
||||
|
||||
These tasks walk you through collaborating with Git in the cloud. You'll clone a shared repository, make changes, and sync with your teammates.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before starting, make sure you have:
|
||||
- [ ] An account on the team's Azure DevOps project
|
||||
- [ ] SSH key configured (ask your facilitator if you need help)
|
||||
- [ ] Git installed on your computer
|
||||
|
||||
---
|
||||
|
||||
## Task 1: Clone the Repository
|
||||
|
||||
Cloning creates a local copy of a remote repository on your computer.
|
||||
|
||||
### Steps
|
||||
|
||||
1. Get the SSH URL from Azure DevOps:
|
||||
- Navigate to the repository
|
||||
- Click **Clone**
|
||||
- Select **SSH**
|
||||
- Copy the URL
|
||||
|
||||
2. Open PowerShell and run:
|
||||
```powershell
|
||||
git clone <paste-the-url-here>
|
||||
```
|
||||
|
||||
3. Open the folder in VS Code:
|
||||
```powershell
|
||||
code <repository-name>
|
||||
```
|
||||
|
||||
4. Open the VS Code terminal (`` Ctrl+` ``) and verify the clone worked:
|
||||
```powershell
|
||||
git status
|
||||
git log --oneline --graph --all
|
||||
```
|
||||
|
||||
### What Just Happened?
|
||||
|
||||
```
|
||||
Azure DevOps Your Computer
|
||||
┌─────────────┐ ┌─────────────┐
|
||||
│ Repository │ ───── clone ──> │ Repository │
|
||||
│ (original) │ │ (copy) │
|
||||
└─────────────┘ └─────────────┘
|
||||
```
|
||||
|
||||
You now have:
|
||||
- A complete copy of all files
|
||||
- The entire commit history
|
||||
- A connection back to the original (called "origin")
|
||||
|
||||
---
|
||||
|
||||
## Task 2: Make Changes and Push
|
||||
|
||||
Pushing sends your local commits to the remote repository.
|
||||
|
||||
### Steps
|
||||
|
||||
1. In VS Code, create a new file:
|
||||
- Click **File → New File** (or `Ctrl+N`)
|
||||
- Add some content, for example: `Hello from <your-name>`
|
||||
- Save as `hello-<your-name>.txt` (use `Ctrl+S`)
|
||||
|
||||
2. In the VS Code terminal, stage and commit your change:
|
||||
```powershell
|
||||
git add .
|
||||
git commit -m "feat: add greeting from <your-name>"
|
||||
```
|
||||
|
||||
3. Push to the remote:
|
||||
```powershell
|
||||
git push
|
||||
```
|
||||
|
||||
### What Just Happened?
|
||||
|
||||
```
|
||||
Your Computer Azure DevOps
|
||||
┌─────────────┐ ┌─────────────┐
|
||||
│ Commit A │ │ Commit A │
|
||||
│ Commit B │ ───── push ───> │ Commit B │
|
||||
│ Commit C │ (new!) │ Commit C │
|
||||
└─────────────┘ └─────────────┘
|
||||
```
|
||||
|
||||
Your new commit is now on the server. Others can see it and download it.
|
||||
|
||||
---
|
||||
|
||||
## Task 3: Pull Changes from Others
|
||||
|
||||
Pulling downloads new commits from the remote and merges them into your branch.
|
||||
|
||||
### Steps
|
||||
|
||||
1. Check if there are new changes:
|
||||
```powershell
|
||||
git status
|
||||
```
|
||||
Look for "Your branch is behind..."
|
||||
|
||||
2. Pull the changes:
|
||||
```powershell
|
||||
git pull
|
||||
```
|
||||
|
||||
3. See what's new:
|
||||
```powershell
|
||||
git log --oneline -10
|
||||
```
|
||||
|
||||
### What Just Happened?
|
||||
|
||||
```
|
||||
Azure DevOps Your Computer
|
||||
┌─────────────┐ ┌─────────────┐
|
||||
│ Commit A │ │ Commit A │
|
||||
│ Commit B │ │ Commit B │
|
||||
│ Commit C │ ───── pull ───> │ Commit C │
|
||||
│ Commit D │ (new!) │ Commit D │
|
||||
└─────────────┘ └─────────────┘
|
||||
```
|
||||
|
||||
Your local repository now has all the commits from the remote.
|
||||
|
||||
---
|
||||
|
||||
## Task 4: The Push-Pull Dance
|
||||
|
||||
When working with others, you'll often need to pull before you can push.
|
||||
|
||||
### The Scenario
|
||||
|
||||
You made a commit, but someone else pushed while you were working:
|
||||
|
||||
```
|
||||
Azure DevOps: A ── B ── C ── D (teammate's commit)
|
||||
Your Computer: A ── B ── C ── E (your commit)
|
||||
```
|
||||
|
||||
### Steps
|
||||
|
||||
1. Try to push:
|
||||
```powershell
|
||||
git push
|
||||
```
|
||||
This will fail with: "Updates were rejected because the remote contains work that you do not have locally"
|
||||
|
||||
2. Pull first:
|
||||
```powershell
|
||||
git pull
|
||||
```
|
||||
|
||||
3. Now push:
|
||||
```powershell
|
||||
git push
|
||||
```
|
||||
|
||||
### What Happened?
|
||||
|
||||
```
|
||||
Before pull:
|
||||
Remote: A ── B ── C ── D
|
||||
Local: A ── B ── C ── E
|
||||
|
||||
After pull (Git merges automatically):
|
||||
Local: A ── B ── C ── D ── M
|
||||
\ /
|
||||
E ───┘
|
||||
|
||||
After push:
|
||||
Remote: A ── B ── C ── D ── M
|
||||
\ /
|
||||
E ───┘
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 5: Understanding Fetch
|
||||
|
||||
Fetch downloads changes but does **not** merge them. This lets you see what's new before deciding what to do.
|
||||
|
||||
### Steps
|
||||
|
||||
1. Fetch updates from the remote:
|
||||
```powershell
|
||||
git fetch
|
||||
```
|
||||
|
||||
2. See what's different:
|
||||
```powershell
|
||||
git log HEAD..origin/main --oneline
|
||||
```
|
||||
This shows commits on the remote that you don't have locally.
|
||||
|
||||
3. When ready, merge:
|
||||
```powershell
|
||||
git merge origin/main
|
||||
```
|
||||
|
||||
### Fetch vs Pull
|
||||
|
||||
| Command | Downloads | Merges | Safe to run anytime? |
|
||||
|---------|-----------|--------|----------------------|
|
||||
| `git fetch` | Yes | No | Yes |
|
||||
| `git pull` | Yes | Yes | Usually |
|
||||
|
||||
**Think of it this way:**
|
||||
- `fetch` = "Show me what's new"
|
||||
- `pull` = "Give me what's new" (same as `fetch` + `merge`)
|
||||
|
||||
---
|
||||
|
||||
## Task 6: Working with Branches
|
||||
|
||||
Branches let you work on features without affecting the main code.
|
||||
|
||||
### Steps
|
||||
|
||||
1. Create and switch to a new branch:
|
||||
```powershell
|
||||
git switch -c feature/<your-name>-greeting
|
||||
```
|
||||
|
||||
2. In VS Code, create a new file:
|
||||
- Click **File → New File** (or `Ctrl+N`)
|
||||
- Add some content, for example: `A special greeting`
|
||||
- Save as `special.txt` (use `Ctrl+S`)
|
||||
|
||||
3. Stage and commit:
|
||||
```powershell
|
||||
git add .
|
||||
git commit -m "feat: add special greeting"
|
||||
```
|
||||
|
||||
4. Push your branch to the remote:
|
||||
```powershell
|
||||
git push -u origin feature/<your-name>-greeting
|
||||
```
|
||||
The `-u` flag sets up tracking so future pushes are simpler.
|
||||
|
||||
5. Go back to main:
|
||||
```powershell
|
||||
git switch main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Task 7: The Number Challenge
|
||||
|
||||
This is the main collaborative exercise. Your team will work together to sort numbers 0-20 into the correct order.
|
||||
|
||||
### The Setup
|
||||
|
||||
The repository contains a file called `numbers.txt` with numbers 0-20 in random order:
|
||||
|
||||
```
|
||||
17
|
||||
3
|
||||
12
|
||||
8
|
||||
...
|
||||
```
|
||||
|
||||
Your goal: Work as a team to rearrange the numbers so they appear in order from 0 to 20.
|
||||
|
||||
### The Rules
|
||||
|
||||
1. **Each person moves ONE number per commit**
|
||||
2. **You must pull before making changes**
|
||||
3. **Communicate with your team** - decide who moves which number
|
||||
|
||||
### Steps
|
||||
|
||||
1. Pull the latest changes:
|
||||
```powershell
|
||||
git pull
|
||||
```
|
||||
|
||||
2. Open `numbers.txt` in VS Code
|
||||
|
||||
3. Find a number that's out of place and move it to the correct position
|
||||
- For example, if `5` is at the bottom, move it between `4` and `6`
|
||||
|
||||
4. Save the file (`Ctrl+S`)
|
||||
|
||||
5. Commit your change with a clear message:
|
||||
```powershell
|
||||
git add numbers.txt
|
||||
git commit -m "fix: move 5 to correct position"
|
||||
```
|
||||
|
||||
6. Push your change:
|
||||
```powershell
|
||||
git push
|
||||
```
|
||||
|
||||
7. If push fails (someone else pushed first):
|
||||
```powershell
|
||||
git pull
|
||||
```
|
||||
Resolve any conflicts, then push again.
|
||||
|
||||
8. Repeat until all numbers are in order!
|
||||
|
||||
### Handling Conflicts
|
||||
|
||||
When two people edit the same part of the file, you'll see conflict markers:
|
||||
|
||||
```
|
||||
<<<<<<< HEAD
|
||||
4
|
||||
5
|
||||
6
|
||||
=======
|
||||
4
|
||||
6
|
||||
>>>>>>> origin/main
|
||||
```
|
||||
|
||||
To resolve:
|
||||
1. Decide what the correct order should be
|
||||
2. Remove the conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`)
|
||||
3. Keep only the correct content:
|
||||
```
|
||||
4
|
||||
5
|
||||
6
|
||||
```
|
||||
4. Save, commit, and push
|
||||
|
||||
### Success
|
||||
|
||||
When complete, `numbers.txt` should look like:
|
||||
|
||||
```
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
```
|
||||
|
||||
Celebrate with your team!
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference
|
||||
|
||||
| Command | What It Does |
|
||||
|---------|--------------|
|
||||
| `git clone <url>` | Download a repository |
|
||||
| `git push` | Upload your commits |
|
||||
| `git pull` | Download and merge commits |
|
||||
| `git fetch` | Download commits (don't merge) |
|
||||
| `git switch -c <name>` | Create and switch to a branch |
|
||||
| `git push -u origin <branch>` | Push a new branch |
|
||||
|
||||
---
|
||||
|
||||
## Common Issues
|
||||
|
||||
### "Permission denied (publickey)"
|
||||
Your SSH key isn't set up correctly. See the SSH setup guide or ask your facilitator.
|
||||
|
||||
### "Updates were rejected"
|
||||
Someone pushed before you. Run `git pull` first, then `git push`.
|
||||
|
||||
### "Merge conflict"
|
||||
Two people edited the same lines. See BEST-PRACTICES.md for how to handle this.
|
||||
|
||||
### "There is no tracking information"
|
||||
Run `git push -u origin <branch-name>` to set up tracking.
|
||||
Reference in New Issue
Block a user