Beginner 6 min · March 06, 2026

GitHub Pull Requests — Force Push Lost 47 Commits

A force push to main deleted 47 commits, blocking production 6 hours.

N
Naren · Founder
Plain-English first. Then code. Then the interview question.
About
 ● Production Incident 🔎 Debug Guide
Quick Answer
  • Branch: your isolated copy of the code where you develop a feature or fix
  • PR description: answers three questions — what changed, why it changed, how to test it
  • Code review: at least one teammate reads your diff line by line before approving
  • Merge strategy: how your commits land on main — merge commit, squash, or rebase
  • Branch protection: rules that enforce reviews, tests, and prevent direct pushes to main
Plain-English First

Imagine you're writing a chapter for a shared school textbook. Before your chapter gets printed, your teacher reads it, suggests edits, and only adds it to the book once everyone agrees it's good. A Pull Request is exactly that — you write your code on your own copy, then formally ask your teammates to read it, suggest changes, and approve it before it becomes part of the main project. The 'review' is the feedback your teacher gives you.

Every professional software team on the planet shares code. Not by emailing zip files or copying folders — they use a structured process where every single change gets proposed, discussed, and approved before it touches the production codebase. GitHub Pull Requests are the mechanism that makes this possible, and they're the beating heart of collaborative software development at companies like Google, Netflix, and Spotify.

Without a review process, one developer's typo can break the app for every user at 2am on a Friday. One misunderstood requirement can send a team down the wrong path for a week. Pull Requests solve this by creating a formal checkpoint: before any code merges into the main branch, at least one other human looks at it. That human catches bugs, asks clarifying questions, and ensures the change actually fits the bigger picture.

The merge strategy you choose — merge commit, squash, or rebase — directly affects how debuggable your history is six months later when you're chasing a regression at 3am. Branch protection rules are what enforce the review process; without them, anyone can push directly to main.

By the end of this article you'll know exactly what a Pull Request is, how to open one from scratch on GitHub, how to leave a code review that your teammates will actually appreciate, and how to avoid the three mistakes that make junior developers cringe in retrospect. You'll also have real terminal commands you can run right now, today.

What Is a Branch and Why You Need One Before a Pull Request

Before you can open a Pull Request, you need to understand branches — because a PR is really just a request to merge one branch into another.

Think of the main branch (often called main or master) as the official published version of your project — the printed textbook. A branch is your personal draft copy where you can experiment, write new features, or fix bugs without touching the published version. Once your work is ready and reviewed, you merge your branch back into main.

Here's the workflow in plain English: you copy the current state of main into a new branch, make your changes there, push that branch to GitHub, and then open a Pull Request to say 'hey team, I've made these changes on my branch — can someone review them before we include them in main?'

The branch name should describe the work you're doing. fix-login-button-alignment is a great branch name. my-branch or test123 will confuse everyone including future you. One branch per feature or bug fix is the golden rule — keep your PRs focused and small.

At production scale, branch naming conventions matter for automation. Teams use prefixes like feature/, fix/, hotfix/, and chore/ so CI/CD pipelines can auto-assign reviewers, auto-label PRs, and trigger different test suites based on branch type. A hotfix/ branch might skip integration tests and deploy directly to staging, while a feature/ branch runs the full suite.

io/thecodeforge/git/create_feature_branch.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Make sure you start from an up-to-date main branch
# This avoids merge conflicts caused by working on stale code
git checkout main
git pull origin main

# Create a new branch with a descriptive name that explains the work
# 'checkout -b' creates the branch AND switches to it in one step
git checkout -b feature/add-user-profile-page

# Confirm you are now on the new branch — the asterisk (*) marks the active branch
git branch

# --- Make your changes to the code here ---
# For this example, we'll create a new file to simulate real work
echo "<h1>User Profile Page</h1>" > user-profile.html

# Stage the new file — 'add' tells Git to track this file in the next commit
git add user-profile.html

# Commit with a message that explains WHAT changed and WHY
# Present tense, imperative mood is the professional standard: 'Add' not 'Added'
git commit -m "Add initial user profile page HTML structure"

# Push this branch up to GitHub so others can see it
# '-u origin' links your local branch to the remote GitHub branch (only needed first time)
git push -u origin feature/add-user-profile-page
Output
Already on 'main'
Your branch is up to date with 'origin/main'.
Switched to a new branch 'feature/add-user-profile-page'
* feature/add-user-profile-page
main
[feature/add-user-profile-page a3f92c1] Add initial user profile page HTML structure
1 file changed, 1 insertion(+)
create mode 100644 user-profile.html
Branch 'feature/add-user-profile-page' set up to track remote branch 'feature/add-user-profile-page' from 'origin'.
To https://github.com/your-username/your-project.git
* [new branch] feature/add-user-profile-page -> feature/add-user-profile-page
Pro Tip: One Branch = One Job
  • Branch names should describe the work: fix-login-button-alignment, not my-branch
  • Use prefixes: feature/, fix/, hotfix/, chore/ — CI/CD pipelines can use these for automation
  • One branch per feature or bug fix — keep PRs focused and small
  • Never work directly on main — always branch off, even for one-line fixes
Production Insight
The most common branch failure in production is working directly on main without branching. When a developer pushes a broken commit to main, every other developer who pulls main gets the broken code. CI/CD deploys the broken code to staging. The fix takes 10 minutes, but the disruption to the team takes an hour. Branch protection rules — requiring PRs before merging to main — prevent this entirely. The second most common failure is stale branches: a developer branches off main, works for 2 weeks, and by the time they open a PR, main has diverged so far that the merge conflict resolution takes longer than the original feature. The fix: rebase onto main daily, not just before opening the PR.
Key Takeaway
One branch per feature, never work directly on main. Rebase onto main daily to avoid merge conflict nightmares. Branch naming conventions (feature/, fix/, hotfix/) enable CI/CD automation. If your branch is older than 2 weeks, rebase before opening the PR.
Branch Creation Decision Tree
IfStarting new work that will take more than 1 commit
UseCreate a feature branch: git checkout -b feature/descriptive-name
IfFixing a bug reported in production
UseCreate a fix branch from main: git checkout -b fix/issue-description
IfEmergency production fix needed immediately
UseCreate a hotfix branch from main: git checkout -b hotfix/critical-issue. Deploy through PR but with expedited review.
IfYou are already on main and have uncommitted changes
UseStash changes first: git stash. Then create branch: git checkout -b feature/name. Then unstash: git stash pop.
IfYour branch is 2+ weeks old and main has diverged significantly
UseRebase onto main before opening PR: git fetch origin && git rebase origin/main. Resolve conflicts locally.

How to Open a Pull Request on GitHub Step by Step

Once your branch is pushed to GitHub, opening the Pull Request takes about two minutes — but writing a good PR description takes a bit more thought, and that effort pays off every single time.

After you push a branch, GitHub usually shows a yellow banner on the repository page saying 'Your recently pushed branch... Compare & pull request'. Click that button. If the banner is gone, click the 'Pull requests' tab, then 'New pull request', and select your branch from the dropdown.

The PR form has three key parts: the title, the description, and the reviewers. The title should be a one-line summary of what the change does. The description is where you explain the context — why does this change exist? What does it do? How can the reviewer test it? A template like 'What, Why, How to Test' makes this systematic.

Assigning reviewers is critical. GitHub lets you request specific people to review your code. In a team setting, at least one approval is typically required before merging. You can also add labels ('bug', 'enhancement'), link to a related issue, and mark a PR as a 'Draft' if it's not ready for review yet — that's a great way to share work-in-progress and get early feedback without it accidentally getting merged.

At senior levels, the PR description is also where you document your design decisions. If you chose Event Sourcing over CRUD, explain why. If you skipped a test type, explain why. Future developers (including future you) will read the PR description when investigating why a piece of code exists. A PR with no description is a black box six months later.

io/thecodeforge/git/pull_request_description_template.mdMARKDOWN
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
## What Does This PR Do?
<!-- One or two sentences. What is the end result of merging this branch? -->
Adds an initial HTML structure for the User Profile page, which will display
the logged-in user's name, avatar, and recent activity feed.

## Why Is This Change Needed?
<!-- Link to the issue or explain the business reason -->
Addresses issue #47 — users currently have no dedicated profile page.
This is the first step in the Q3 personalisation milestone.

## How to Test It
<!-- Tell the reviewer exactly what steps to follow to verify the change works -->
1. Pull this branch locally: `git fetch && git checkout feature/add-user-profile-page`
2. Open `user-profile.html` in a browser
3. Confirm the heading 'User Profile Page' renders correctly
4. Confirm no existing pages are broken by checking `index.html` still loads

## Design Decisions (if applicable)
<!-- Document WHY you chose this approach over alternatives -->
- Chose server-side rendering over client-side SPA for this page because
  the profile data is static and SEO is a requirement.
- Used PostgreSQL `jsonb` column for user preferences instead of a separate
  table because the data is read-heavy and rarely queried independently.

## Risk Assessment
<!-- For changes touching critical paths -->
- Risk level: Lowthis is a new page with no dependencies on existing flows.
- Rollback plan: revert this PR. No database migrations involved.

## Screenshots (if relevant)
<!-- Drag and drop images here — essential for any UI changes -->
[Before: no profile page exists]
[After: /user-profile.html shows heading]

## Checklist
- [x] I have tested this change locally
- [x] I have added comments to complex code sections
- [ ] I have updated the documentation (not needed for this change)
- [x] No new console errors or warnings introduced
Output
-- This is a Markdown template, not runnable code --
When pasted into the GitHub PR description box, GitHub renders it as:
A formatted description with bold headings, a numbered test list,
an image drop zone, and interactive checkboxes that teammates
can tick as they verify each item.
Draft PRs Are Your Secret Weapon
  • Draft PRs cannot be merged accidentally — GitHub enforces this
  • Use Draft PRs to get architecture feedback before writing all the code
  • Convert to 'Ready for Review' when done — GitHub auto-notifies assigned reviewers
  • Draft PRs are especially useful for large features where you want early buy-in on the approach
Production Insight
The single biggest thing that slows down code reviews is a bad PR description. When a reviewer opens a PR and sees 'fixed stuff' or no description at all, they have to read every line of code to understand what changed and why. This turns a 10-minute review into a 45-minute archaeology session. The fix: spend 5 minutes writing a description that answers what, why, and how to test. This saves the reviewer 30 minutes and gets your code merged faster. At the team level, PR description templates enforced through GitHub's .github/PULL_REQUEST_TEMPLATE.md file ensure every PR follows the same structure. The second biggest bottleneck is missing reviewers — a PR with no assigned reviewers sits in limbo. Always assign at least one reviewer when you open the PR.
Key Takeaway
A PR description answers three questions: what changed, why it changed, how to test it. Skipping this is the single biggest thing that slows down code reviews. Use Draft PRs for early feedback. Always assign at least one reviewer. At senior level, document design decisions and risk assessments in the PR description.
PR Description Decision Tree
IfPR touches only one file with a clear, self-explanatory change
UseMinimal description is acceptable: one-line summary + link to issue. Add screenshots if UI changed.
IfPR touches multiple files or introduces a new pattern
UseFull description required: what, why, how to test, design decisions. Include a risk assessment.
IfPR touches a critical path (auth, payments, data migrations)
UseFull description + risk assessment + rollback plan. Tag a senior reviewer even if not required by branch rules.
IfPR is a work-in-progress and you want early feedback
UseOpen as Draft PR. Description can be lighter — focus on 'here is what I am thinking, does this approach make sense?'
IfPR has no description and reviewer asks clarifying questions
UseStop. Write the description before answering questions. Every question the reviewer asks is a question the description should have answered.

How to Do a Code Review That Actually Helps

Being asked to review code is a responsibility, not a chore. A good review catches real bugs, shares knowledge across the team, and makes the codebase better. A bad review is either rubber-stamping everything or leaving vague, discouraging comments.

On GitHub, click the 'Files changed' tab in a PR to see a side-by-side diff — the red lines are what was removed, the green lines are what was added. You can click the '+' icon that appears when you hover over any line to leave an inline comment on that specific line.

There are three things to look for when reviewing: correctness (does it actually work?), clarity (can I understand what this code does in 30 seconds?), and consistency (does it follow the patterns the rest of the codebase uses?).

When you leave a comment, be specific and constructive. Instead of 'this is wrong', say 'this function will throw a null reference error if the user has no profile photo set — what if we add a fallback here?' GitHub lets you prefix comments with Nitpick: for minor style preferences so the author knows what's critical versus optional.

When you're done reviewing, click 'Review changes' and choose one of three options: Comment (general feedback, no decision), Approve (looks good to merge), or Request Changes (specific issues that must be fixed first). Only approve when you'd genuinely be comfortable with this code shipping.

At the senior level, code review is also about architectural consistency. Does this new service follow the same error handling pattern as the rest of the codebase? Does it use the same logging format? Does it introduce a new dependency that the team needs to evaluate? These are the questions that separate a senior review from a junior review.

io/thecodeforge/service/user_profile_service.jsJAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// This is the kind of code you might review in a PR
// The inline comments below simulate what a good reviewer would flag

// REVIEWER COMMENT on line 3:
// 'getUserData' is too vague. What kind of data? Rename to 'fetchUserProfileById'
// to make the intent clear without reading the implementation.
function getUserData(id) {

  // REVIEWER COMMENT on line 7:
  // No input validation here. What happens if 'id' is null, undefined,
  // or a negative number? This will hit the API and potentially return
  // confusing errors. Suggest adding: if (!id || id <= 0) return null;
  const apiUrl = `https://api.example.com/users/${id}`;

  return fetch(apiUrl)
    .then(function(serverResponse) {
      // REVIEWER COMMENT on line 14:
      // We should check serverResponse.ok before calling .json()
      // If the API returns a 404 or 500, .json() will still run
      // and we'll get a misleading error, not a clear 'user not found'.
      return serverResponse.json();
    })
    .then(function(userData) {
      return userData;
    })
    // REVIEWER APPROVE NOTE:
    // Good job adding a .catch() — error handling is often forgotten.
    // Consider logging the error to your monitoring service here too.
    .catch(function(networkError) {
      console.error('Failed to fetch user profile:', networkError);
      return null;
    });
}

// IMPROVED VERSION after review feedback:
function fetchUserProfileById(userId) {
  // Guard clause — fail fast with a clear reason
  if (!userId || userId <= 0) {
    console.warn('fetchUserProfileById called with invalid userId:', userId);
    return Promise.resolve(null);
  }

  const profileApiUrl = `https://api.example.com/users/${userId}`;

  return fetch(profileApiUrl)
    .then(function(serverResponse) {
      // Explicitly check for HTTP errors before parsing the body
      if (!serverResponse.ok) {
        throw new Error(`User profile API returned status: ${serverResponse.status}`);
      }
      return serverResponse.json();
    })
    .then(function(userProfileData) {
      return userProfileData;
    })
    .catch(function(networkError) {
      console.error('Failed to fetch user profile:', networkError.message);
      return null;
    });
}
Output
-- No runtime output for this example --
The value here is the inline review comments that demonstrate
what a senior developer looks for:
1. Naming clarity (getUserData -> fetchUserProfileById)
2. Input validation (guard clause for invalid userId)
3. HTTP error handling (checking serverResponse.ok)
4. Constructive tone: explains the WHY, not just 'this is wrong'
Watch Out: Approving Without Reading
  • Rubber-stamping approvals lets bugs reach production — your approval is a safety gate
  • If a PR is too large to review, say so explicitly: 'please split this into smaller PRs'
  • Use 'Request Changes' when there are specific issues that must be fixed — do not just leave comments and approve
  • Prefix minor style feedback with 'Nitpick:' so the author knows what is critical vs optional
Production Insight
The most damaging code review anti-pattern is rubber-stamping: clicking 'Approve' without actually reading the code. This happens when reviewers are overloaded, when the PR is too large, or when the team culture treats reviews as a formality. The result: bugs reach production that a 10-minute review would have caught. The fix: enforce review quality through branch protection rules (require at least one approval), keep PRs small (200-400 lines), and create a team norm where 'Request Changes' is expected and not taken personally. The second anti-pattern is scope creep in reviews: a reviewer sees a PR to fix a login bug and leaves comments about the CSS on a completely unrelated page. Keep review comments scoped to the PR's stated purpose. If you see unrelated issues, open a separate issue or PR — do not hijack the current review.
Key Takeaway
Review for correctness, clarity, and consistency. Be specific and constructive — explain the WHY, not just 'this is wrong'. Never rubber-stamp approvals. If a PR is too large, say so and ask for it to be split. Approval means 'I'd be comfortable if this shipped right now.' Use Nitpick prefix for optional style feedback.
Code Review Decision Tree
IfPR is small (<100 lines), change is clear, tests pass
UseReview for correctness and consistency. If no issues: Approve. If minor style issues: Comment with Nitpick prefix, then Approve.
IfPR is medium (100-400 lines), touches multiple files
UseReview for correctness, clarity, consistency, and test coverage. Check for edge cases. If issues found: Request Changes with specific line references.
IfPR is large (400+ lines) or touches critical paths (auth, payments, DB migrations)
UseRequest the author to split the PR. If splitting is not possible, schedule a pair review session. Do not rubber-stamp.
IfReviewer disagrees with the author's approach
UseLeave a comment explaining your concern and suggesting an alternative. Use 'I'd suggest...' not 'You should...'. If the author explains their reasoning and it is sound, Approve.
IfPR has been open for 5+ days with no resolution
UseEscalate to tech lead. A stale PR blocks the team. Either merge with a follow-up issue, or close and rework.

Merging a Pull Request and Keeping History Clean

Once a PR has the required approvals and all CI checks pass (tests, linting, etc.), it's ready to merge. GitHub gives you three merge strategies and picking the right one matters for keeping your Git history readable.

'Create a merge commit' preserves every commit from your branch and adds a merge commit on top. This is great for long-running features where you want to see the full development history.

'Squash and merge' takes all your commits and compresses them into a single commit on main. This is perfect for small features or bug fixes where your branch had messy 'WIP' or 'fix typo' commits that aren't worth preserving. The result is a clean, linear history.

'Rebase and merge' replays your branch commits directly on top of main without a merge commit, keeping history linear. It's the cleanest option but can cause confusion if your branch had public commits others were building on.

After merging, always delete the feature branch — GitHub shows a 'Delete branch' button right after the merge. Stale branches pile up fast and confuse the whole team. Locally, run git branch -d to clean up too.

If the PR has merge conflicts — meaning main changed in ways that clash with your branch — you'll need to resolve them before merging. GitHub can handle simple conflicts in the browser, but for complex ones, resolve them locally.

At the production level, the merge strategy you choose affects how debuggable your history is. When you're chasing a regression at 3am using git bisect, a clean linear history (from squash or rebase) makes bisect dramatically faster. A branched history with 50 merge commits makes bisect nearly unusable because each merge commit is a diff of diffs.

io/thecodeforge/git/merge_and_cleanup.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# --- After your PR is approved and merged on GitHub ---
# Switch back to main and pull the freshly merged changes
git checkout main
git pull origin main

# Confirm your feature branch changes are now part of main
# The --oneline flag shows a compact one-line-per-commit view
git log --oneline -5

# Delete the local feature branch — the work is done, the branch is no longer needed
# '-d' (lowercase) is safe: it refuses to delete if the branch hasn't been merged yet
git branch -d feature/add-user-profile-page

# Confirm the branch is gone from your local machine
git branch

# --- If you need to resolve a merge conflict before merging ---
# First, pull the latest main into your feature branch to surface the conflict locally
git checkout feature/add-user-profile-page
git fetch origin
git merge origin/main

# Git will tell you which files have conflicts, e.g.:
# CONFLICT (content): Merge conflict in user-profile.html
# Open that file — you'll see conflict markers like this:
# <<<<<<< HEAD  (your changes)
# <h1>User Profile</h1>
# =======  (what's in main)
# <h1>User Details</h1>
# >>>>>>> origin/main

# Edit the file to keep the correct version, then:
git add user-profile.html
git commit -m "Resolve merge conflict: keep User Profile heading from feature branch"
git push origin feature/add-user-profile-page
# Now your PR on GitHub can be merged cleanly

# --- Verifying merge strategy on GitHub ---
# Check what merge options are available:
# Go to repo Settings > General > Pull Requests
# Options: Allow merge commits, Allow squash merging, Allow rebase merging
# Enable the ones your team uses, disable the rest to enforce consistency
Output
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
Already up to date.
a3f92c1 Add initial user profile page HTML structure
7b2e4d9 Update navigation links in header
3c8f1a2 Fix broken image path on homepage
9d4c7e8 Add footer contact information
1e5b0f3 Initial project setup
Deleted branch feature/add-user-profile-page (was a3f92c1).
* main
Pro Tip: Squash for Cleaner History
  • Squash and Merge collapses all branch commits into one clean commit on main
  • Use for small features and bug fixes where individual commit history doesn't matter
  • Do NOT squash when commit history is important for debugging (e.g., refactors where each step matters)
  • After merging, always delete the feature branch — stale branches confuse the team
Production Insight
The merge strategy you choose has a direct impact on debugging speed six months later. When you're chasing a regression using git bisect, a clean linear history (from squash or rebase) makes bisect fast and reliable — each commit is a meaningful unit of change. A branched history with dozens of merge commits makes bisect nearly unusable because merge commits are diffs-of-diffs, and bisect can land on a merge commit that represents 30 changes at once. The trade-off: squash loses the individual commit history, which can be valuable for understanding the development process of a complex feature. The rule: squash for small, self-contained changes. Merge commit for large, multi-developer features where the commit-by-commit history is part of the documentation. The second production issue is stale branches: after merging, if you don't delete the branch, it stays in the remote. After 6 months, the repo has 200 stale branches and nobody knows which ones are safe to delete. Configure GitHub to auto-delete branches after merge (Settings > General > 'Automatically delete head branches').
Key Takeaway
Squash for small features and bug fixes — keeps main's history clean. Merge commit for large features where commit-by-commit history matters. Rebase for linear history with preserved commits. Always delete branches after merging. The merge strategy you choose affects how debuggable your history is when chasing regressions at 3am.
Merge Strategy Decision Tree
IfSmall feature or bug fix with messy WIP commits
UseSquash and Merge. One clean commit on main. History stays linear and readable.
IfLarge feature with meaningful commit-by-commit history
UseMerge Commit. Preserves the full development history. Useful when the commit messages document the evolution of the feature.
IfYou want linear history but individual commits matter
UseRebase and Merge. Replays commits on top of main without a merge commit. Cleanest history but use only when the branch has clean, meaningful commits.
IfBranch has merge conflicts with main
UseResolve locally first: git fetch origin && git merge origin/main. Fix conflicts, push, then merge on GitHub. Do not resolve complex conflicts in the GitHub web editor.
IfPR is merged and branch is no longer needed
UseDelete the branch immediately. On GitHub: click 'Delete branch' after merge. Locally: git branch -d branch-name. Configure GitHub to auto-delete branches after merge.
● Production incidentPOST-MORTEMseverity: high

Force Push to Main: 47 Commits Lost, Production Deploy Blocked for 6 Hours

Symptom
A junior developer was working on a feature directly on the main branch (they didn't know about branches). When they tried to push, Git rejected it because their local copy was behind remote. They ran git push --force and overwrote 47 commits from 5 other developers. The CI/CD pipeline deployed the old code. Production broke within minutes.
Assumption
The junior developer assumed the force push was just 'updating their code to match what they had locally.' They didn't understand that force push replaces the remote history entirely — it doesn't merge, it overwrites. They also didn't know about branches, which would have isolated their work from main.
Root cause
1. The repository had no branch protection rules — anyone could push directly to main without a PR or review. 2. The junior developer had never been taught about branches — they were working directly on main. 3. When their push was rejected (because main had moved ahead), they googled 'git push rejected' and found --force as the solution. 4. The force push replaced the remote main branch history with their local history, which was 47 commits behind. 5. CI/CD automatically deployed the overwritten code to production. 6. The team had no backup strategy — the only recovery option was Git reflog on machines that still had the correct commits.
Fix
1. Immediate: identified the last known good commit SHA from the CI/CD pipeline logs and team members' local reflogs. 2. Recovered the lost commits using git reflog on the senior developer's machine (they had the most recent pull). 3. Force-pushed the correct history back to main from the recovered reflog. 4. Configured branch protection rules: require PR reviews, require CI checks to pass, disable force push to main. 5. Added a pre-push hook that warns when pushing to main without a PR. 6. Result: production restored in 6 hours. No data was permanently lost because team members had local copies.
Key lesson
  • Never force push to a shared branch — main, develop, or any branch others depend on. Force push replaces history; it does not merge.
  • Always work on a feature branch, never directly on main. One branch per feature is the golden rule.
  • Branch protection rules are not optional — they are the safety net that prevents catastrophic mistakes. Require PR reviews and CI checks before merging.
  • If you get a 'rejected' push error, the answer is never --force. The answer is git pull --rebase to incorporate remote changes first.
Production debug guideSystematic resolution paths for the most common PR and review failures in team workflows.5 entries
Symptom · 01
PR shows 50+ files changed and reviewers refuse to review it
Fix
1. The PR is too large — reviewers cannot review 50 files in one sitting. 2. Close the current PR. Split the work into 3-5 smaller PRs, each focused on one logical change. 3. Open the first small PR, get it reviewed and merged, then open the next. 4. Rule of thumb: if a PR takes more than 30 minutes to review, it is too large. Target 200-400 lines of diff per PR. 5. If the changes are truly inseparable, add a detailed PR description explaining why splitting is not possible, and offer to walk the reviewer through it on a call.
Symptom · 02
CI/CD pipeline fails on your PR but passes locally
Fix
1. Read the CI failure log — click the red 'X' on the PR and open the failing job. 2. Check for environment differences: CI runs on Linux, your machine may be macOS. Check for case-sensitive file paths, missing environment variables, or OS-specific dependencies. 3. Check for missing secrets: CI may not have access to API keys or tokens that are in your local .env file. 4. Reproduce locally: run the same commands CI runs (check the CI config file — .github/workflows/ for GitHub Actions). 5. If tests pass locally but fail in CI, the most common cause is timing-dependent tests (flaky tests) or missing test data setup.
Symptom · 03
PR has merge conflicts and GitHub says 'This branch has conflicts that must be resolved'
Fix
1. Do NOT resolve conflicts in the GitHub web editor for complex conflicts — it is error-prone. 2. Locally: git checkout your-branch && git fetch origin && git merge origin/main. 3. Open the conflicted files — Git marks conflicts with <<<<<<<, =======, >>>>>>> markers. 4. Decide which version to keep (or combine both), remove the markers, save the file. 5. Run git add on the resolved files, then git commit to complete the merge. 6. Push the updated branch — the PR on GitHub will update automatically.
Symptom · 04
Reviewer keeps requesting changes and the PR has been open for 2 weeks
Fix
1. This is a review bottleneck, not a code problem. Schedule a 15-minute pair review session with the reviewer. 2. Walk through the code together on a screen share — synchronous review is 5x faster than async comment threads. 3. If the reviewer is raising scope-creep concerns (adding new requirements not in the original ticket), escalate to the tech lead to clarify scope. 4. If the reviewer is unreachable, reassign to another reviewer. A stale PR blocks the entire team. 5. After merge, retro: why did this PR take 2 weeks? Was it too large? Was the reviewer overloaded? Fix the root cause.
Symptom · 05
PR was approved and merged but broke production within hours
Fix
1. Immediate: revert the merge commit. On GitHub, go to the PR and click 'Revert' — this creates a new PR that undoes the changes. 2. Merge the revert PR immediately to restore production. 3. Root cause analysis: why did the review not catch the bug? Was the test coverage insufficient? Was the reviewer unfamiliar with the code area? 4. Add a regression test that would have caught the bug. 5. Update the PR template to include a 'Risk Assessment' section for changes that touch critical paths.
★ Pull Request Triage Cheat SheetFast resolution paths for the most common PR failures. Use when a PR is blocking you or your team right now.
Merge conflict on PR — GitHub says 'cannot merge automatically'
Immediate action
Resolve locally, not in GitHub web editor
Commands
git checkout your-branch && git fetch origin && git merge origin/main
git diff --name-only --diff-filter=U (lists conflicted files)
Fix now
Open conflicted files, remove conflict markers, keep correct version, git add + git commit + git push
CI pipeline fails on PR — tests pass locally+
Immediate action
Read the CI failure log first, do not re-run hoping it passes
Commands
cat .github/workflows/*.yml (find what CI actually runs)
Run CI commands locally to reproduce: npm test / ./mvnw test / pytest
Fix now
Check for: missing env vars, OS-specific paths, flaky tests, missing test data
PR too large — 50+ files, reviewers refuse to review+
Immediate action
Close PR, split into 3-5 focused PRs of 200-400 lines each
Commands
git log --oneline main..your-branch (see all commits in the PR)
git rebase -i main (interactive rebase to split commits into logical groups)
Fix now
Create separate branches for each logical group, open separate PRs, link them in descriptions
Accidental force push to main — history overwritten+
Immediate action
Do NOT push anything else. Find the last good commit SHA immediately.
Commands
git reflog (find the last known good commit on your machine or a teammate's)
git reset --hard <good-commit-sha> && git push --force-with-lease origin main
Fix now
Configure branch protection rules to disable force push to main. This should never happen again.
PR branch is 50+ commits behind main — massive diff that isn't yours+
Immediate action
Rebase your branch onto the latest main to isolate your actual changes
Commands
git fetch origin && git rebase origin/main
git diff origin/main (verify only your changes appear in the diff)
Fix now
Force push the rebased branch: git push --force-with-lease origin your-branch. The PR diff will now show only your changes.
Merge Strategies Compared
AspectMerge CommitSquash and MergeRebase and Merge
History styleBranched (non-linear)Linear — one clean commitLinear — all commits replayed
Individual commits preserved?Yes — every commit keptNo — squashed into oneYes — but rebased onto main
Best forLong-running feature branchesSmall features, bug fixesClean commit history fans
Merge commit added?YesYes (squash commit)No
Risk level for beginnersLow — safest optionLow — very popular choiceMedium — can cause confusion
When to avoidWhen branch has 20 'wip' commitsWhen commit history matters for debuggingWhen others branched off your branch
git bisect friendlinessPoor — merge commits are diffs-of-diffsExcellent — each commit is a meaningful unitGood — linear but individual commits preserved
Team convention recommendationUse for features > 1 week of workDefault for most PRs — cleanest main historyUse when individual commits tell a story

Key takeaways

1
A Pull Request is a formal request to merge one branch into another
it's the review checkpoint that stands between your code and production, not just a Git feature.
2
A great PR description answers three questions
What changed, why it changed, and how to test it — skipping this is the single biggest thing that slows down code reviews.
3
Approve means 'I'd be comfortable if this shipped right now'
never click Approve to be polite; a hollow approval that lets a bug through is worse than a delayed review.
4
Squash and Merge keeps main's history readable by collapsing messy WIP commits into one clean entry
prefer it for small features and bug fixes unless individual commit history matters for debugging.
5
One branch per feature, never work directly on main. Rebase onto main daily to avoid merge conflict nightmares. Branch protection rules are not optional
they are the safety net.
6
Review for correctness, clarity, and consistency. Be specific and constructive. If a PR is too large, say so and ask for it to be split. Scope-creep in reviews hijacks the process.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

FAQ · 5 QUESTIONS

Frequently Asked Questions

01
What is the difference between a pull request and a merge request?
02
How many people need to approve a pull request before it can be merged?
03
Can I keep committing to my branch after opening a pull request?
04
What is --force-with-lease and why is it safer than --force?
05
How do I split a large PR into smaller ones?
🔥

That's Git. Mark it forged?

6 min read · try the examples if you haven't

Previous
Git Workflows — GitFlow
6 / 19 · Git
Next
Git Tags and Releases