⚡ ~/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 49 of 52 in Git & Branching Workflows
Staff SRE / Principal Architect [L3] Git Amend without editing message Staff SRE Scenario [L3]
🎯 Target Role / Context: Git Scenario #49 (L3) · Amend without editing message

Q: Your monorepo CI is slow because every PR triggers tests for all 30 services. How would you use Git to determine which services are affected by a PR and only run their tests?

Use git diff to identify changed paths and map them to affected services:

#Git #L3 #Version Control #Collaboration
🎙️ Candidate Opening & Architectural Context
""In a fast-paced team with dozens of pull requests merged daily, Git workflow hygiene was critical. The interviewer is testing: Using Git diff for selective CI, path-based triggering.. 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: "In a fast-paced team with dozens of pull requests merged daily, Git workflow hygiene was critical. The interviewer is testing: Using Git diff for selective CI, path-based triggering.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."

1️⃣

Initial Diagnostics & Root Cause Analysis

Use git diff to identify changed paths and map them to affected services:

  • Bazel/Pants/Buck — build systems that understand the dependency graph and test only affected targets: bazel test //... --test_tag_filters=-manual with remote caching.
  • Nx/Turborepo (JS/TS monorepos) — nx affected --target=test automatically determines what to test based on the Git diff.
  • git diff with --diff-filter — distinguish added, modified, deleted, and renamed files for more precise mapping.
2️⃣

Remediation & Permanent Safeguards

Step 1: Get changed files in the PR: The three-dot syntax (...) finds the merge-base and shows only what the PR changed — not what main changed since the branch was created. Step 2: Map changed paths to services: This mapping can be a simple bash script, a JSON config file, or defined in CI config: Step 3: Handle shared dependencies: The tricky part. If libs/common/ changes, every service that depends on it must be tested. Maintain a dependency graph (or use build tools like Bazel, Nx, or Turborepo that understand it natively). Advanced approaches: The key insight: git diff --name-only gives you the raw data; the intelligence is in the mapping from file paths to services/test suites.

# Compare PR branch against the merge target:
CHANGED_FILES=$(git diff --name-only origin/main...HEAD)
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Bazel/Pants/Buck — build systems that understand the dependency graph and test only affected targets: bazel test //... --test_tag_."
⚡ 60-Second Elevator Pitch Talking Points
  • Bazel/Pants/Buck — build systems that understand the dependency graph and test only affected targ...
  • Nx/Turborepo (JS/TS monorepos) — nx affected --target=test automatically determines what to test ...
  • git diff with --diff-filter — distinguish added, modified, deleted, and renamed files for more pr...
⛔ 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 monorepo slow every 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 monorepo slow every 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 monorepo slow every 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 monorepo slow every 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 →