2.8 KiB
2.8 KiB
Multiplayer Git
Work with others using branches and pull requests.
Goal
Learn to collaborate on a shared repository using:
- Branches - work independently without breaking main
- Pull Requests - review and merge changes safely
The Workflow
1. Create branch → 2. Make changes → 3. Push branch
↓
6. Delete branch ← 5. Merge PR ← 4. Create PR
This is how professional teams work together on code.
Step 1: Clone the Repository
Get the repository URL from your facilitator, then:
git clone <repository-url>
code <repository-name>
Step 2: Create a Branch
Never work directly on main. Create your own branch:
git switch -c <branch>
This creates a new branch and switches to it.
Step 3: Make Changes
- Open
numbers.txtin VS Code - Move one number to its correct position
- Save the file (
Ctrl+S)
Step 4: Commit and Push
git add .
git commit -m "fix: move 7 to correct position"
git push feature-2
Your branch is now on Azure DevOps.
Step 5: Create a Pull Request
- Go to Azure DevOps in your browser
- Navigate to Repos → Pull Requests
- Click New Pull Request
- Set:
- Source branch:
feature/<your-name> - Target branch:
main
- Source branch:
- Add a title describing your change
- Click Create
Step 6: Review and Merge
- Review the changes shown in the PR
- If everything looks good, click Complete
- Select Complete merge
- Your changes are now in
main
Step 7: Update Your Local Main
After merging, update your local copy:
git switch main
git pull
Step 8: Repeat
- Create a new branch for your next change
- Make changes, commit, push
- Create another PR
- Continue until all numbers are sorted
Quick Reference
| Command | What It Does |
|---|---|
git switch -c <name> |
Create and switch to new branch |
git push -u origin <branch> |
Push branch to Azure DevOps |
git switch main |
Switch to main branch |
git pull |
Get latest changes from remote |
Common Issues
"I accidentally committed to main"
Switch to a new branch and push from there:
git switch -c feature/<your-name>
git push -u origin feature/<your-name>
"My PR has conflicts"
- Update your branch with latest main:
git switch main git pull git switch feature/<your-name> git merge main - Resolve conflicts in VS Code
- Commit and push again
"I need to make more changes to my PR"
Just commit and push to the same branch - the PR updates automatically:
git add .
git commit -m "fix: address review feedback"
git push