⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Git & Branching Workflows Interview Questions Scenario 4 of 52 in Git & Branching Workflows
Senior DevOps / SRE [L2] Git Branching, Merging & Conflicts Production Scenario [L2]
🎯 Target Role / Context: Git Scenario #4 (L2) · Branching, Merging & Conflicts

Q: When should you use `git rebase` instead of `git merge`, and what is the one rule you must never break?

Both integrate changes from one branch into another, but they produce very different histories.

#Git #L2 #Version Control #Collaboration #Rebase
🎙️ Candidate Opening & Architectural Context
""Git is an immutable directed acyclic graph (DAG); knowing commands like git reflog means you never truly lose commits. The interviewer is testing: Workflow tradeoffs, understanding the danger of rewriting shared history.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: "Git is an immutable directed acyclic graph (DAG); knowing commands like git reflog means you never truly lose commits. The interviewer is testing: Workflow tradeoffs, understanding the danger of rewriting shared history.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."

1️⃣

Initial Diagnostics & Root Cause Analysis

Both integrate changes from one branch into another, but they produce very different histories.

  • Merge preserves the actual branching history (creates a merge commit). Good for main/release branches where the history of *when things converged* matters.
  • Rebase replays your commits on top of the target branch, producing a linear history with no merge commits. Good for cleaning up your local feature branch *before* opening a PR — it makes review easier and git log readable.
2️⃣

Remediation & Permanent Safeguards

The one rule: never rebase commits that have been pushed and that other people are working on. Rebase rewrites commit hashes. If a teammate has pulled the old commits and you force-push rewritten ones, their next pull is a mess and they may re-introduce the old commits. Rebase your private branch all you want; never rebase shared branches like main or develop. Common workflow: rebase your feature branch onto latest main (git pull --rebase origin main), squash interactively (git rebase -i), force-push to your *own* feature branch, then merge the PR.

💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Merge preserves the actual branching history (creates a merge commit). Good for main/release branches where the history of *when t."
⚡ 60-Second Elevator Pitch Talking Points
  • Merge preserves the actual branching history (creates a merge commit). Good for main/release bran...
  • Rebase replays your commits on top of the target branch, producing a linear history with no merge...
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring rebase instead merge git push --force unconditionally overwrites remote commits made by teammates, whereas --force-with-lease aborts if the remote ref was updated.
  2. Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring rebase instead merge Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
  3. Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring rebase instead merge git reflog tracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches.
  4. Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring rebase instead merge Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.
Advertisement
Want more Git & Branching Workflows scenarios?
Explore our complete collection of scenario-based Git & Branching Workflows interview runbooks.
Browse All Git & Branching Workflows Questions →