Q: Design a branch-protection and merge-policy setup for a regulated environment (PCI / SOC 2) with 30 services in a monorepo. Walk me through the controls you'd put on `main` and how they interact with developer ergonomics.
Compliance auditors essentially want to see: every change to main is reviewed by someone other than the author, every change is traced to a ticket, every change runs the same controls, and the history is tamper-evident.
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: Holistic policy design balancing compliance, security, and velocity.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
Compliance auditors essentially want to see: every change to main is reviewed by someone other than the author, every change is traced to a ticket, every change runs the same controls, and the history is tamper-evident.
- No direct pushes — pushes only via PR.
Restrict who can push to matching branchesset to no one (not even admins, withDo not allow bypassingenabled). - Linear history required — no merge commits. Forces squash- or rebase-merge, making each
maincommit a single reviewable, revertable unit. - Required reviews — minimum 1 for low-risk paths, 2 for sensitive paths via CODEOWNERS.
Dismiss stale reviewson new commits so a reviewer's approval doesn't carry over after the author force-pushes. - CODEOWNERS mapping critical paths (
/infra/,/auth/,/billing/,/.github/workflows/) to specific owners. Workflows-on-workflows is a common attack vector — protect.github/aggressively. - Required status checks — CI must pass: unit tests, integration tests, SAST (e.g. Semgrep), dependency scan (Dependabot/Snyk/Trivy), secret scan (gitleaks), license scan, and the duplicate-Q&A or contract-tests if relevant. Pin the exact check names so they can't be renamed away.
- Signed commits required — see prior answer.
- Conversation resolution required — every PR comment must be resolved before merge.
- No bypass for admins — auditors will ask. The tradeoff: a real emergency (rare) requires temporarily lifting the rule, which is logged in the audit trail and is itself a finding to triage.
- Ticket linking — PR title regex enforced to include
JIRA-1234(or similar). Thecommit-msghook on the server rejects PRs without it. Auditors get traceability from ticket → PR → commit → deployment.
Remediation & Permanent Safeguards
Controls on main: Process controls layered on top: Where this hits ergonomics: The principle: make the secure path the easy path. If the protected workflow is faster than circumventing it (because of good tooling, fast CI, and sane PR sizes), engineers stays on it; the policy then enforces itself culturally rather than only via lockdown.
- PR templates — checkboxes for "tests added," "security impact considered," "rollback plan." Required for sensitive areas via CODEOWNERS-driven PR templates.
- Production deploy gating —
mainis continuously deployed to staging, but production promotion goes through a separate change-management workflow (ServiceNow, Linear, etc.) with the deploying engineer different from the commit author. Many auditors require this segregation of duties. - Audit log retention — Git host audit logs (GitHub Enterprise, GitLab Premium) retained 1+ year and shipped to your SIEM. The audit log captures every protection-rule change, force-push attempt, and admin override.
- Two reviewers required on
/auth/slows urgent fixes — mitigate with a documented break-glass process and clear on-call ownership. - Required signed commits adds setup friction for new hires — build it into the laptop bootstrap script and have the onboarding checklist verify a signed test commit before they get repo write access.
- Many required checks → slow merges. Invest in CI parallelism and selective testing (run only the affected service's tests when paths under
services/foo/change). Without this, developers will route around the system, defeating the policy. - "No bypass for admins" feels paranoid until you're sitting in a SOC 2 audit; lean into it and design the emergency process upfront so engineers know what to do without disabling controls.
- No direct pushes — pushes only via PR. Restrict who can push to matching branches set to no one (...
- Linear history required — no merge commits. Forces squash- or rebase-merge, making each main comm...
- Required reviews — minimum 1 for low-risk paths, 2 for sensitive paths via CODEOWNERS. Dismiss st...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Running raw git push --force rather than git push --force-with-lease on shared team feature branches when configuring Design branch protection
git push --forceunconditionally overwrites remote commits made by teammates, whereas--force-with-leaseaborts if the remote ref was updated. - Resolving complex merge conflicts with blind checkout overwrite strategies without running unit tests when configuring Design branch protection Unilateral conflict resolution frequently clobbers complementary logic introduced in parallel feature branches, creating regression bugs.
-
Discarding corrupted working directories prematurely instead of recovering lost state using git reflog when configuring Design branch protection
git reflogtracks every HEAD movement, allowing instant recovery of discarded commits, botched rebases, or deleted local branches. - Disabling branch protection rules and mandatory PR approval reviews on shared release branches when configuring Design branch protection Without branch protection, developers can bypass CI validation gates and push untested code directly to production branches.