From a07b8f1f1823ac830e9f82181b09a17ae39d391a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Almeida?= Date: Thu, 14 May 2026 00:05:50 +0100 Subject: [PATCH] fix(worktree): push to the branch's configured upstream remote, not hard-coded origin PushEnvironmentBranch was running `git push origin `, which breaks for repos whose primary remote isn't called "origin" (fork workflows that use "upstream", "github", etc.). Read the branch's configured upstream remote via `git config branch..remote` and fall back to "origin" only when no upstream is set. --- apps/backend/cmd/kandev/worktree.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/backend/cmd/kandev/worktree.go b/apps/backend/cmd/kandev/worktree.go index ecd24d1f4b..8a2002cde1 100644 --- a/apps/backend/cmd/kandev/worktree.go +++ b/apps/backend/cmd/kandev/worktree.go @@ -164,7 +164,12 @@ func (a *environmentDestroyerAdapter) PushEnvironmentBranch(ctx context.Context, if branch == "" { cmd = exec.CommandContext(pushCtx, "git", "push") } else { - cmd = exec.CommandContext(pushCtx, "git", "push", "origin", branch) + // Prefer the branch's configured upstream remote so this works for + // repos whose primary remote isn't called "origin" (e.g. fork + // workflows with "upstream"/"github"). Fall back to "origin" only + // when no upstream is set, matching the historical behaviour. + remote := detectBranchRemote(pushCtx, env.WorktreePath, branch) + cmd = exec.CommandContext(pushCtx, "git", "push", remote, branch) } cmd.Dir = env.WorktreePath // Disable interactive credential prompts — without this, a missing @@ -180,3 +185,20 @@ func (a *environmentDestroyerAdapter) PushEnvironmentBranch(ctx context.Context, } return nil } + +// detectBranchRemote reads the configured upstream remote for `branch` from +// the worktree's git config. Falls back to "origin" when no upstream is set +// (matching the historical hard-coded behaviour). +func detectBranchRemote(ctx context.Context, dir, branch string) string { + cmd := exec.CommandContext(ctx, "git", "config", "--get", "branch."+branch+".remote") + cmd.Dir = dir + out, err := cmd.Output() + if err != nil { + return "origin" + } + remote := strings.TrimSpace(string(out)) + if remote == "" { + return "origin" + } + return remote +}