Skip to content

Commit 1beb775

Browse files
committed
Set upstream tracking when creating worktree for existing local branch
When a local branch already exists and a matching remote branch is found, the worktree was created without configuring upstream tracking. This meant git pull/push required manual upstream setup.
1 parent 9dc946e commit 1beb775

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/git-wt/Commands.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public static int Create(string branchName)
4141
{
4242
Console.WriteLine($"Using existing branch '{branchName}'...");
4343
exitCode = Git.RunLive(bareRepoPath, "worktree", "add", worktreePath, branchName);
44+
45+
if (exitCode == 0 && remoteBranchExists)
46+
Git.Run(bareRepoPath, "branch", $"--set-upstream-to=origin/{branchName}", branchName);
4447
}
4548
else if (remoteBranchExists)
4649
{

0 commit comments

Comments
 (0)