8.4 KiB
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
-
Get the SSH URL from Azure DevOps:
- Navigate to the repository
- Click Clone
- Select SSH
- Copy the URL
-
Open PowerShell and run:
git clone <paste-the-url-here> -
Open the folder in VS Code:
code <repository-name> -
Open the VS Code terminal (
Ctrl+`) and verify the clone worked: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
-
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(useCtrl+S)
- Click File → New File (or
-
In the VS Code terminal, stage and commit your change:
git add . git commit -m "feat: add greeting from <your-name>" -
Push to the remote:
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
-
Check if there are new changes:
git statusLook for "Your branch is behind..."
-
Pull the changes:
git pull -
See what's new:
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
-
Try to push:
git pushThis will fail with: "Updates were rejected because the remote contains work that you do not have locally"
-
Pull first:
git pull -
Now push:
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
-
Fetch updates from the remote:
git fetch -
See what's different:
git log HEAD..origin/main --onelineThis shows commits on the remote that you don't have locally.
-
When ready, merge:
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 asfetch+merge)
Task 6: Working with Branches
Branches let you work on features without affecting the main code.
Steps
-
Create and switch to a new branch:
git switch -c feature/<your-name>-greeting -
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(useCtrl+S)
- Click File → New File (or
-
Stage and commit:
git add . git commit -m "feat: add special greeting" -
Push your branch to the remote:
git push -u origin feature/<your-name>-greetingThe
-uflag sets up tracking so future pushes are simpler. -
Go back to main:
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
- Each person moves ONE number per commit
- You must pull before making changes
- Communicate with your team - decide who moves which number
Steps
-
Pull the latest changes:
git pull -
Open
numbers.txtin VS Code -
Find a number that's out of place and move it to the correct position
- For example, if
5is at the bottom, move it between4and6
- For example, if
-
Save the file (
Ctrl+S) -
Commit your change with a clear message:
git add numbers.txt git commit -m "fix: move 5 to correct position" -
Push your change:
git push -
If push fails (someone else pushed first):
git pullResolve any conflicts, then push again.
-
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:
- Decide what the correct order should be
- Remove the conflict markers (
<<<<<<<,=======,>>>>>>>) - Keep only the correct content:
4 5 6 - 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.