🌐 Phase 2 · Remote Collaboration 🟡 Intermediate MODULE 06

GitHub Workflow

⏱️ 50 min
💻 Hands-on
🧩 5 Quiz Questions
🏗️ 1 Challenge
Course progress75%
🎯 What you'll learn: The GitHub Flow — the industry-standard workflow for teams. Creating and reviewing Pull Requests. Forking repos to contribute to open source. Managing work with GitHub Issues and labels. Protecting your main branch with branch protection rules. Resolving conflicts that arise in Pull Requests.

GitHub Flow — The Industry Standard

GitHub Flow is a lightweight, branch-based workflow that teams use everywhere from startups to Fortune 500 companies. It has one rule: main is always deployable. All work happens in branches and only lands in main via a Pull Request.

1
Create a branch
Branch off main with a descriptive name: feat/user-auth, fix/login-bug, docs/api-guide
2
Make commits
Make your changes in small, focused commits with clear messages. Commit often — each commit is a save point.
3
Push your branch
Push your branch to GitHub: git push -u origin feat/user-auth. This makes it visible to your team.
4
Open a Pull Request
On GitHub, open a PR from your branch to main. Write a clear title and description explaining your changes.
5
Review & discuss
Teammates review the code, leave comments, request changes. You push more commits to address feedback.
6
Merge
Once approved and CI passes, merge the PR. GitHub auto-deletes the branch (optional). Deploy if needed.
The full GitHub Flow in commands
BASH
# 1. Start from latest main
git switch main
git pull origin main

# 2. Create your feature branch
git switch -c feat/user-auth

# 3. Make commits as you work
git add .
git commit -m "feat: add JWT authentication middleware"

# 4. Push your branch to GitHub
git push -u origin feat/user-auth
# GitHub will suggest opening a Pull Request — click the link!

Creating Pull Requests

A Pull Request (PR) is a formal request to merge your branch into another (usually main). It's where code review happens — teammates can see exactly what changed, comment on specific lines, and approve or request changes before merging.

📝
Writing a great PR description
A good PR tells reviewers: What changed and Why. Include: a summary of changes, screenshots if it's a UI change, testing steps ("I tested by..."), and reference any related issues ("Closes #42"). Reviewers shouldn't have to guess your intent.

On GitHub, after pushing your branch you'll see a yellow banner: "Compare & pull request". Click it, then fill in:

Title: Clear and concise — "feat: add user authentication with JWT" is better than "auth stuff"
Description: What does this PR do? Why was it needed? Any caveats?
Reviewers: Tag specific teammates who should review
Labels: bug, enhancement, documentation, etc.
Linked Issues: Use Closes #42 to auto-close an issue when merged

Code Review

Code review is one of the most valuable practices in software development. It catches bugs before production, spreads knowledge through the team, and maintains code quality standards. As a reviewer, your goal is to be constructive, not critical.

✅ Good Review Comments
  • "This function could be simplified using reduce..."
  • "Have you considered the edge case where X is null?"
  • "Nit: rename to `userData` for clarity"
  • "Great approach! One thought: could we cache this?"
❌ Unhelpful Comments
  • "This is wrong"
  • "I don't like this"
  • "Why would you do it this way?"
  • "LGTM" (with no actual review done)

Review states: Comment (general feedback, no decision), Approve (looks good, ready to merge), Request Changes (must be addressed before merging). Most teams require at least one approval before merging to main.

Forking Repositories

Forking creates your own copy of someone else's repository on GitHub. Unlike cloning (which just downloads), a fork is a full GitHub repo under your account that you can push to freely. Forks are the foundation of open source contribution.

The open source contribution workflow
BASH
# 1. Fork on GitHub (click the Fork button on the repo page)
#    This creates: github.com/YOUR_USERNAME/original-repo

# 2. Clone YOUR fork (not the original)
git clone git@github.com:YOUR_USERNAME/original-repo.git
cd original-repo

# 3. Add the original as "upstream" remote
git remote add upstream git@github.com:ORIGINAL_OWNER/original-repo.git

# 4. Create a branch for your change
git switch -c fix/typo-in-readme

# 5. Make your change, commit it
git add . && git commit -m "fix: correct typo in installation guide"

# 6. Push to YOUR fork
git push origin fix/typo-in-readme
# Then open a PR from YOUR fork to the ORIGINAL repo on GitHub

# Keep your fork up to date with upstream changes
git fetch upstream
git merge upstream/main

GitHub Issues

GitHub Issues are the task tracker built into every repository. Use them to report bugs, request features, ask questions, or plan work. Issues integrate tightly with PRs — you can automatically close an issue when a PR merges.

🔗
Auto-closing issues with commit messages
Include keywords in your PR title or commit message to automatically close related issues when the PR merges:
Closes #42, Fixes #17, Resolves #8
When the PR merges into the default branch, GitHub automatically closes the referenced issue and adds a link between them.

Labels help categorize issues: bug, enhancement, good first issue, help wanted, documentation. The good first issue label is used by open source projects to mark beginner-friendly tasks — a great way to start contributing.

Milestones group issues by version or sprint: "v2.0 Release" or "Sprint 3". They give a high-level view of how much work is done vs remaining toward a goal.

Branch Protection Rules

Branch protection rules prevent accidental or unauthorized changes to critical branches. Most teams protect main so no one can push directly — all changes must go through a PR.

🛡️
Protect your main branch
Go to your repo → Settings → Branches → Add rule. Set the branch name pattern to main. Common protections: Require a pull request before merging (no direct pushes), Require approvals (at least 1 reviewer), Require status checks to pass (CI must pass), Include administrators (even repo owners follow the rules).

With branch protection enabled, even if you have write access to the repo, git push origin main will be rejected with a "protected branch" error. This forces the PR workflow and prevents the classic "whoops, pushed broken code to production" scenario.

Resolving PR Conflicts

When a PR can't be merged because main has moved ahead and the changes conflict, you need to resolve the conflicts locally and push again. There are two approaches: merge (simpler) or rebase (cleaner history).

Resolving PR conflicts via merge or rebase
BASH
### Option 1: Merge approach (simpler)
git switch feat/my-feature
git fetch origin
git merge origin/main
# Resolve any conflicts in your editor
git add .
git commit -m "merge: sync with main"
git push

### Option 2: Rebase approach (cleaner history)
git switch feat/my-feature
git fetch origin
git rebase origin/main
# Resolve conflicts if any, then:
git rebase --continue
git push --force-with-lease
# Use --force-with-lease, not --force (safer)
⚠️
--force-with-lease vs --force
After rebasing, you'll need to force push because you've rewritten history. Always use --force-with-lease instead of --force — it will fail if someone else pushed to the branch since you last fetched, preventing you from overwriting their work.
🧩 Knowledge Check — Lesson 6
Test your GitHub Workflow knowledge. 5 questions.
1. What is a Pull Request?
2. In GitHub Flow, after creating a feature branch you should:
3. Forking is primarily used to:
4. What does writing Closes #42 in a PR description do?
5. Branch protection rules on main primarily prevent:
🔀
Workflow Challenge — Lesson 6
Fork, branch, and open a PR · Intermediate
Challenge: Your First Open Source-Style Contribution

1. Find any public GitHub repo (try github.com/firstcontributions/first-contributions)
2. Click Fork to create your own copy under your account
3. Clone your fork: git clone git@github.com:YOUR_USERNAME/first-contributions.git
4. Create a branch: git switch -c feature/your-name
5. Add a file: contributors/your-name.md with a short bio
6. Commit: git commit -m "feat: add your-name to contributors"
7. Push: git push -u origin feature/your-name
8. On GitHub, open a Pull Request from your fork to the original repo
9. Write a proper PR description explaining what you added
💡 Show hints
  • GitHub will show a "Compare & pull request" button after you push — click it
  • Your PR goes from YOUR FORK's branch to the ORIGINAL REPO's main
  • The PR title and description are the first things maintainers see — make them clear
  • first-contributions repo is specifically designed for beginner PRs — they welcome them!
Finished this lesson?
Mark it complete to track your progress.
🎉

Lesson 6 Complete!

You know the professional GitHub workflow. Time to go advanced with Git's power tools.

Lesson 06 of 09Git & GitHub Mastery