⚡ ~/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) →
Senior DevOps / SRE [L2] Git ... fix the bug, commit, push ... Production Scenario [L2]

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 #... fix the bug, commit, push ... #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

🛠️ Production Runbook & Step-by-Step Resolution

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

📚 Related Production Scenarios in Git