Interview Prep/Git & GitHub/Branching and Merging Workflows

You are mid-feature and an urgent bug needs a fix on another branch. You don't want to stash or commit half-done work. What do you do?

IntermediateScenarioBranching and Merging Workflows
Answer

Situation read → Switching branches would disturb your working tree.

What I'd do →

  1. Create a second working directory on the same repo:
git worktree add ../hotfix-wt -b hotfix/login origin/main
cd ../hotfix-wt
  1. Fix, test, push from there.
  2. Clean up: git worktree remove ../hotfix-wt.

Why → Worktrees share one object database, so there is no second clone and no stash juggling. Each branch can only be checked out in one worktree at a time.

Interview tip → Worktrees are also great for running a long test suite on one branch while coding on another.

All Git & GitHub questions Roadmap: Git & GitHub

More on Branching and Merging Workflows