⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 998+ 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) →
Staff SRE / Principal Architect [L3] Git Amend without editing message Staff SRE Scenario [L3]

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 #Amend without editing message #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

🛠️ Production Runbook & Step-by-Step Resolution

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...
Advertisement
Want more Git scenarios?
Explore our complete collection of scenario-based Git interview runbooks.
Browse All Git Questions →

📚 Related Production Scenarios in Git