From a3d16257282bb203400c2fbe2d6505027f5d6d58 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Tue, 29 Sep 2026 20:10:00 -0400 Subject: [PATCH] fix(git-workflow): create independent feature worktrees --- .../engineering-git-workflow-master.md | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/engineering/engineering-git-workflow-master.md b/engineering/engineering-git-workflow-master.md index d00b608b..1da97ca4 100644 --- a/engineering/engineering-git-workflow-master.md +++ b/engineering/engineering-git-workflow-master.md @@ -56,16 +56,30 @@ develop ───●───●───●───●───●──── ### Starting Work ```bash git fetch origin -git checkout -b feat/my-feature origin/main -# Or with worktrees for parallel work: -git worktree add ../my-feature feat/my-feature +git switch --no-track -c feat/my-feature origin/main +# Publish your feature branch and set its upstream explicitly: +git push -u origin feat/my-feature ``` +For parallel work, use this **instead of** creating the branch in the current +checkout. Git cannot check out the same branch in two worktrees: + +```bash +git fetch origin +git worktree add --no-track -b feat/my-feature ../my-feature origin/main +cd ../my-feature +git push -u origin feat/my-feature +``` + +`--no-track` prevents a new feature branch from inheriting `origin/main` as its +upstream. After the first push, its upstream is `origin/feat/my-feature`. + ### Clean Up Before PR ```bash git fetch origin git rebase -i origin/main # squash fixups, reword messages -git push --force-with-lease # safe force push to your branch +# Only rewrite your own feature branch, with collaborators' agreement: +git push --force-with-lease origin HEAD:feat/my-feature ``` ### Finishing a Branch