I have a project containing some private files, such as API keys, database files, and personal settings, stored in different directories:
./src/database/*.json
./src/config/*.private.*
To keep a versioned backup of those files that I can clone on any device, I created a separate Git repository inside the src directory with its own .gitignore configured to include only the necessary files.
I use the VS Code Source Control interface to manage repositories. VS Code correctly detects both repositories (the main project repository and the nested backup repository), allowing me to manage them separately.
However, the nested repository's .gitignore seems to affect the entire workspace instead of only its own repository. As a result, files ignored in the nested repository are also treated as ignored in the main repository.
Example:
What I currently see:
src changes:
- .gitignore src
- api-keys.private.json
- settings.private.json
project changes:
- .gitignore
- .gitignore src
- api-keys.private.json
- settings.private.json
What I expected:
src changes:
- .gitignore src
- api-keys.private.json
- settings.private.json
project changes:
- .gitignore
- other-files.js
What I want is to keep both repositories nested and manage them independently in VS Code, each using its own .gitignore rules.
I found that .git/info/exclude could be used instead of .gitignore, but since it is local and not versioned, I would prefer to avoid that solution.
Is there a proper way to configure nested repositories in VS Code so that each repository respects only its own .gitignore file?