File tree Expand file tree Collapse file tree 1 file changed +23
-5
lines changed
Expand file tree Collapse file tree 1 file changed +23
-5
lines changed Original file line number Diff line number Diff line change @@ -909,12 +909,30 @@ export function registerCommands(
909909 // Continue even if fetch fails - the branch might already be available locally
910910 }
911911
912+ // Check if the branch already exists locally
913+ let branchExists = false ;
914+ try {
915+ await repositoryToUse . getBranch ( branchName ) ;
916+ branchExists = true ;
917+ } catch {
918+ // Branch doesn't exist locally, we'll create it
919+ branchExists = false ;
920+ }
921+
912922 // Use the git extension's createWorktree API
913- await repositoryToUse . createWorktree ! ( {
914- path : worktreePath ,
915- commitish : trackedBranchName ,
916- branch : branchName
917- } ) ;
923+ // If branch already exists, don't specify the branch parameter to avoid "branch already exists" error
924+ if ( branchExists ) {
925+ await repositoryToUse . createWorktree ! ( {
926+ path : worktreePath ,
927+ commitish : branchName
928+ } ) ;
929+ } else {
930+ await repositoryToUse . createWorktree ! ( {
931+ path : worktreePath ,
932+ commitish : trackedBranchName ,
933+ branch : branchName
934+ } ) ;
935+ }
918936 }
919937 ) ;
920938
You can’t perform that action at this time.
0 commit comments