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 worktree for parallel development.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
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."
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 listshows all worktrees.
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-worktreecleans it up when done.- Worktrees share refs — a commit made in one worktree is immediately visible in the other (they share
.git).
- ~/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...
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
-
Using deprecated git filter-branch rather than modern git filter-repo to scrub committed credentials
git filter-branchis slow, error-prone, and frequently leaves dangling blobs, whereasgit filter-repocleanly purges sensitive files. - 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.
- 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.
- 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.