git - 如何在 VS Code 中使用远程跟踪创建本地 git 分支

标签 git visual-studio-code

从私有(private) git 服务器 pull 时,每当我在 VS Code 中创建一个分支时,它都不会跟踪上游分支。 git 输出显示它正在运行

git checkout -q -b NewBranchLocal --no-track origin/NewBranch

如果我使用“>Git: checkout 到...”或“>Git:从...创建分支”命令。

是否有从 git 服务器中提取这些内容的最佳实践?如何在 VS Code 中使用 git 扩展来创建原始分支的本地版本并将其绑定(bind)到该上游分支?

从我在 VS Code 的源代码中看到的内容来看,似乎 --no-track 应该只在您正在创建的分支被 checkout 时显示,但我没有看到一个选项您可以创建一个分支而不检查它。查看 vscode-master/extensions/git/src 文件夹,git.ts(第 1238 行)说

    async branch(name: string, checkout: boolean, ref?: string): Promise<void> {
        const args = checkout ? ['checkout', '-q', '-b', name, '--no-track'] : ['branch', '-q', name];

        if (ref) {
            args.push(ref);
        }

        await this.run(args);
    }

唯一的引用是在 repository.ts(第 979 行)中:

    async branch(name: string, _checkout: boolean, _ref?: string): Promise<void> {
        await this.run(Operation.Branch, () => this.repository.branch(name, _checkout, _ref));
    }

这是在 commands.ts 文件中调用的(第 1563 行)

    private async _branch(repository: Repository, defaultName?: string, from = false): Promise<void> {
        const branchName = await this.promptForBranchName(defaultName);

        if (!branchName) {
            return;
        }

        let target = 'HEAD';

        if (from) {
            const picks = [new HEADItem(repository), ...createCheckoutItems(repository)];
            const placeHolder = localize('select a ref to create a new branch from', 'Select a ref to create the \'{0}\' branch from', branchName);
            const choice = await window.showQuickPick(picks, { placeHolder });

            if (!choice) {
                return;
            }

            target = choice.label;
        }

        await repository.branch(branchName, true, target);
    }

因此无法不检查该分支,也没有机会将新的本地分支链接到源。

我在 vscode-master 项目中找不到任何其他引用资料,所以我不知道下一步该去哪里。

最佳答案

根据 this VS Code issue , Git: Checkout to... 命令会显示一个分支列表。如果您选择一个远程分支,它将创建一个本地分支并将其设置为跟踪远程分支。我刚刚使用 VS Code 1.47.3 对此进行了测试,它创建了具有跟踪功能的本地分支。也许他们在您将问题发布到此处后解决了这个问题?

关于git - 如何在 VS Code 中使用远程跟踪创建本地 git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57699396/

相关文章:

visual-studio-code - 在 VSCode 中使用制表符保留缩进或缩进的间距

python - 视觉代码 pylint : unable to import webapp2 and google. appengine.api

visual-studio-code - 如何在 VSCode 中将键盘快捷键设置为 "Terminate Running Task"?

git - rebase 以压缩同一分支上的多个提交

git - 如果没有所有提交,如何停止 merge github 分支

git - 如何在不覆盖本地文件的情况下从远程 pull 文件?

Git clone fatal error ,用户凭据正确

editor - 如何更改所选文本和选择/单词匹配的突出显示?

python - 运行 main() 项目文件的快捷方式

git - 您能否在不造成冲突的情况下恢复除最后一次提交以外的提交?