๐Ÿ”€

Advanced Git & Collaboration

๐Ÿ‘จโ€๐Ÿณ Chef

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

ElementWhat to include
TitleClear and concise description
DescriptionWhat it does, why, how to test
ScreenshotsIf there are visual changes
TestsAll passing
SizeSmall (< 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

PracticeWhy it helps
Small PRsLess code = fewer conflicts
Merge main frequentlyDetect conflicts early
Communication"I'm modifying X" in chat
Separate filesEveryone 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?

SituationUse
PR to mainMerge (or Squash)
Update your branch with mainRebase
Shared branch with othersMerge (never rebase)
Clean historyRebase + Squash

โš ๏ธ Golden rule: Never rebase branches that others are using.


๐Ÿ‘ฅ Branching strategies

GitHub Flow (simple, recommended)

main โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€โ—โ”€โ”€โ”€โ”€
          \      /   \      /
           โ—โ”€โ”€โ”€โ”€โ—     โ—โ”€โ”€โ”€โ”€โ—
          feature    feature
  • main always 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 forExample
BugsDoes it handle errors? Edge cases?
SecuritySQL injection? XSS? Secrets?
PerformanceN+1 queries? Unnecessary loops?
ReadabilityUnderstandable without explanation?
TestsCover 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

VersionWhen 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