gitvisual-studio-codevscode-git

How can I prevent VS Code from auto-detecting git repositories in parent directories of the current workspace?


I just joined a project with a lot of sub-projects and terrible .gitignore definition, ending up with VS Code scanning 5000+ changes across the solution and ignoring the changes that I just made.

I tried to open the sub-project I'm working on in VS Code but it still attaches to the parent .git and scans the whole solution.

Is there any VS Code configuration I'd be missing that would have Git focus on the current directory rather than the whole solution, considering that I'm working on an offline environment without extensions ?

Also, would avoid the obvious 'just update your .gitignore' answer ...


Solution

  • You're probably looking for the git.openRepositoryInParentFolders setting. Quoting defaultSettings.json:

    // Control whether a repository in parent folders of workspaces or open files should be opened.
    //  - always: Always open a repository in parent folders of workspaces or open files.
    //  - never: Never open a repository in parent folders of workspaces or open files.
    //  - prompt: Prompt before opening a repository the parent folders of workspaces or open files.
    "git.openRepositoryInParentFolders": "prompt",
    

    It defaults to "prompt", so you should have gotten a prompt about it...


    Okay, the asker clarified that they're on VS Code 1.57. That's... a pretty old version of VS Code now. I'd suggest to update. Anyhow, that explains it. The setting I mention above was added in VS Code 1.75. As mentioned in the release notes, the behaviour prior to 1.75 is essentially the same as "git.openRepositoryInParentFolders": "always".

    Note that there is also a feature to close repositories (see How can I ignore a whole git repository in Visual Studio Code?).