⚡ ~/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 25 of 52 in Git & Branching Workflows
Senior DevOps / SRE [L2] Git ... fix the bug, commit, push ... Production Scenario [L2]
🎯 Target Role / Context: Git Scenario #25 (L2) · ... fix the bug, commit, push ...

Q: You need to work on two branches of the same repo simultaneously — for example, testing a fix on `release/2.0` while actively developing on `feature/new-api`. Switching branches back and forth is painful because of build artifacts and IDE reindexing. What's the solution?

Use git worktree to check out multiple branches simultaneously in separate directories, all backed by the same .git database:

#Git #L2 #Version Control #Collaboration #Terraform State
🎙️ 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: Awareness of git worktree for parallel development.. 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: Awareness of git worktree for parallel development.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."

1️⃣

Initial Diagnostics & Root Cause Analysis

Use git worktree to check out multiple branches simultaneously in separate directories, all backed by the same .git database:

  • ~/projects/my-repo/ → feature/new-api
  • ~/projects/release-2.0-worktree/ → release/2.0
  • A branch can only be checked out in one worktree at a time. Git enforces this to prevent conflicting index states.
  • git worktree list shows all worktrees.
2️⃣

Remediation & Permanent Safeguards

Now you have two working directories: Each has its own working tree, index, and HEAD, but they share the same object store, refs, and config. No extra disk space for the Git history. Key rules: This is vastly better than cloning the repo twice (which doubles disk usage and requires separate fetches) and avoids the constant stash/switch/pop dance.

# From your main checkout (on feature/new-api):
git worktree add ../release-2.0-worktree release/2.0
  • git worktree remove ../release-2.0-worktree cleans it up when done.
  • Worktrees share refs — a commit made in one worktree is immediately visible in the other (they share .git).
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: ~/projects/my-repo/ → feature/new-api."
⚡ 60-Second Elevator Pitch Talking Points
  • ~/projects/my-repo/ → feature/new-api
  • ~/projects/release-2.0-worktree/ → release/2.0
  • A branch can only be checked out in one worktree at a time. Git enforces this to prevent conflict...
⛔ 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. Using deprecated git filter-branch rather than modern git filter-repo to scrub committed credentials git filter-branch is slow, error-prone, and frequently leaves dangling blobs, whereas git filter-repo cleanly purges sensitive files.
  2. Pushing large compiled binary artifacts, disk images, or zip packages into standard Git repository history Git tracks every binary version permanently; bloating repository size slows git clone and fetch operations across all team members.
  3. Rebasing or amending commits that have already been published and merged into upstream main branches Rewriting published history forces all collaborators to perform complex manual reconciliations and corrupts continuous delivery tracking.
  4. Failing to rotate leaked credentials immediately under the false assumption that rewriting Git history revokes access in git-q025-you-need-to-work-on-two-branches-of Once pushed to a remote repository, secrets must be treated as fully compromised regardless of subsequent git history rewriting.
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 →