Skip to content

Commit 48f2ee8

Browse files
committed
Enables creating branches without remote tracking
Introduces a `noTracking` option to the `checkout` operation, allowing `git checkout -b --no-track` to be used. The `GitRepositoryService.switch` method now supports this option, which is leveraged by the `branch create --switch` command. When creating a local branch from a remote branch with a different name, the command will now use `--no-track` to prevent automatic setup of a remote tracking branch. (#5360)
1 parent 4e6b765 commit 48f2ee8

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

packages/git-cli/src/providers/operations.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,18 @@ export class OperationsGitSubProvider implements GitOperationsSubProvider {
5252
async checkout(
5353
repoPath: string,
5454
ref: string,
55-
options?: { createBranch?: string },
55+
options?: { createBranch?: string; noTracking?: boolean },
5656
runOptions?: GitOperationRunOptions,
5757
): Promise<void> {
5858
const scope = getScopedLogger();
5959

6060
const params = ['checkout'];
6161
if (options?.createBranch) {
62-
params.push('-b', options.createBranch, ref, '--');
62+
params.push('-b', options.createBranch);
63+
if (options.noTracking) {
64+
params.push('--no-track');
65+
}
66+
params.push(ref, '--');
6367
} else {
6468
params.push(ref, '--');
6569
}

src/commands/git/branch/create.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ export class BranchCreateGitCommand extends QuickCommand<State> {
263263
steps.markStepsComplete();
264264

265265
if (state.flags.includes('--switch')) {
266-
await state.repo.git.switch(state.reference.ref, { createBranch: state.name });
266+
await state.repo.git.switch(state.reference.ref, {
267+
createBranch: state.name,
268+
...(isRemoteBranch && state.name !== remoteBranchName ? { noTracking: true } : undefined),
269+
});
267270
} else {
268271
try {
269272
await state.repo.git.branches.createBranch?.(

src/git/gitRepositoryService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,10 @@ export class GitRepositoryService {
513513

514514
@gate()
515515
@debug()
516-
async switch(ref: string, options?: { createBranch?: string | undefined; progress?: boolean }): Promise<void> {
516+
async switch(
517+
ref: string,
518+
options?: { createBranch?: string | undefined; noTracking?: boolean; progress?: boolean },
519+
): Promise<void> {
517520
const { progress, ...opts } = { progress: true, ...options };
518521
if (!progress) return this.switchCore(ref, opts);
519522

@@ -528,7 +531,7 @@ export class GitRepositoryService {
528531
);
529532
}
530533

531-
private async switchCore(ref: string, options?: { createBranch?: string }) {
534+
private async switchCore(ref: string, options?: { createBranch?: string; noTracking?: boolean }) {
532535
try {
533536
await this.ops?.checkout(ref, options);
534537
} catch (ex) {

0 commit comments

Comments
 (0)