Professional collaboration with Git
You know how to use Git alone. Now learn to work in a team without stepping on other developers' toes.
๐ Pull Requests (PRs)
A PR is a request to integrate your changes into the main branch. It's the heart of collaboration.
PR workflow
# 1. Create a branch for your feature
git checkout -b feature/new-functionality
# 2. Work and make commits
git add .
git commit -m "Add contact form"
# 3. Push your branch
git push -u origin feature/new-functionality
# 4. Create the PR on GitHub
gh pr create --fill
# Or go to GitHub and click "Compare & pull request"
Anatomy of a good PR
| Element | What to include |
|---|---|
| Title | Clear and concise description |
| Description | What it does, why, how to test |
| Screenshots | If there are visual changes |
| Tests | All passing |
| Size | Small (< 400 lines ideal) |
PR description example
## What does this PR do?
Adds contact form with validation.
## Why?
Users need to be able to contact us (#123)
## How to test?
1. Go to /contact
2. Fill out the form
3. Verify the email arrives
## Screenshots
[form image]
## Checklist
- [x] Tests pass
- [x] No console.logs
- [x] Responsive
โ๏ธ Merge Conflicts
They happen when two people modify the same lines. Don't panic.
What they look like
<<<<<<< HEAD
const message = "Main version";
=======
const message = "Your version";
>>>>>>> feature/my-branch
How to resolve them
# 1. Update your branch with main
git checkout feature/my-branch
git fetch origin
git merge origin/main
# Conflicts appear here
# 2. Open files with conflicts
# VS Code marks them in red/green
# 3. Decide which code to keep
# Remove the <<<<, ====, >>>> markers
# 4. Mark as resolved
git add file-with-conflict.js
git commit -m "Resolve conflicts with main"
git push
Tips to avoid conflicts
| Practice | Why it helps |
|---|---|
| Small PRs | Less code = fewer conflicts |
| Merge main frequently | Detect conflicts early |
| Communication | "I'm modifying X" in chat |
| Separate files | Everyone in their zone |
๐ Rebase vs Merge
Two ways to integrate changes. Both valid, different uses.
Merge (preserves history)
git checkout main
git merge feature/my-branch
A---B---C feature
/ \
D---E---F---G---H main (merge commit)
Rebase (linear history)
git checkout feature/my-branch
git rebase main
git checkout main
git merge feature/my-branch # Fast-forward
D---E---F---G---A'---B'---C' main
When to use each?
| Situation | Use |
|---|---|
| PR to main | Merge (or Squash) |
| Update your branch with main | Rebase |
| Shared branch with others | Merge (never rebase) |
| Clean history | Rebase + Squash |
โ ๏ธ Golden rule: Never rebase branches that others are using.
๐ฅ Branching strategies
GitHub Flow (simple, recommended)
main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\ / \ /
โโโโโโ โโโโโโ
feature feature
mainalways deployable- Features in short-lived branches
- PRs for everything
- Deploy after merge
GitFlow (large enterprises)
main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
/ /
release โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
/ / / /
develop โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\ / \ /
โโโโโ โโโโโ
feature feature
- More complex, more control
- Branches: main, develop, feature, release, hotfix
- For planned releases
Trunk-Based (expert teams)
main โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
\โ/ \โ/ \โ/
tiny tiny tiny
- Direct commits to main (or very small PRs)
- Feature flags for incomplete code
- Robust CI/CD required
๐ Code Review
Reviewing others' code is as important as writing it.
As PR author
# Before requesting review
git diff main...HEAD # Review your changes
npm test # Ensure tests pass
npm run lint # No style errors
As reviewer
| Look for | Example |
|---|---|
| Bugs | Does it handle errors? Edge cases? |
| Security | SQL injection? XSS? Secrets? |
| Performance | N+1 queries? Unnecessary loops? |
| Readability | Understandable without explanation? |
| Tests | Cover important cases? |
How to give constructive feedback
โ "This is wrong"
โ
"Consider using Optional Chaining here to avoid
the error if user is undefined: user?.name"
โ "I don't like it"
โ
"I'd prefer extracting this logic to a separate function
to improve testability. What do you think?"
๐ท๏ธ Semantic Versioning
How to number releases: MAJOR.MINOR.PATCH
| Version | When to increment |
|---|---|
| MAJOR (2.0.0) | Breaking changes |
| MINOR (1.1.0) | New functionality, compatible |
| PATCH (1.0.1) | Bug fixes |
# Create a version tag
git tag -a v1.2.0 -m "Release 1.2.0: Add authentication"
git push origin v1.2.0
# List tags
git tag -l
# Create GitHub release
gh release create v1.2.0 --notes "Changelog here"
๐ ๏ธ Useful advanced commands
# Squash: Combine last 3 commits into one
git rebase -i HEAD~3
# Change "pick" to "squash" on commits to combine
# Cherry-pick: Bring a specific commit
git cherry-pick abc123
# Stash: Save changes temporarily
git stash
git stash pop
# Bisect: Find which commit introduced a bug
git bisect start
git bisect bad # Current commit has bug
git bisect good v1.0.0 # This version was fine
# Git guides you until finding the culprit
# Reflog: Recover "lost" commits
git reflog
git checkout HEAD@{2}
# Clean: Remove untracked files
git clean -fd
๐ Collaboration checklist
- Branch with descriptive name (
feature/,fix/,hotfix/) - Atomic commits with clear messages
- PR with complete description
- Tests pass in CI
- Code review approved
- No conflicts with main
- Squash or merge per team convention
๐ณ Practice
โ Contribute to Open Source โ Your first PR to a real project
Useful links
- ๐ GitHub Flow
- ๐ Conventional Commits
- ๐ Semantic Versioning
- ๐ Learn Git Branching