I have the following folder structure..where _app, and _infra are two different projects. At the root of the workspace however are two files, the workspace project file itself and a .gitignore file.
Each project has it’s own .vscode folder and own .env files.
The entire workspace is a single repository in git.
my_app_workspace
- proj1_app/
- .venv/ (virtual environment)
- vscode/
- settings.json
- launch.json
- task.json
- src/
- config.py
- .env
- .env_linux
- proj1_infra/
- vscode/
- settings.json
- launch.json
- task.json
- src/
- config.py
- .env
- .env_linux
- .git_ignore
- my_app_workspace.code-workspace
the code-workspace file looks like this:
{
"folders": [
{
"path": "./proj1_app"
},
{
"path": "./proj1_infra"
}
],
}
This is all good, but i want to include the .git_ignore and my_app_workspace.code-workspace files also into the vscode editor so that i can easy make modifications to them.
I know i can add another folder with ‘"path": "."’, but this will add a folder with the project folders again – which seems redundant and not efficient.
Is there a way to add individual files to the workspace? Is the problem here i should simply split these up into two different repository in git? this way each has it’s own .gitignore file as opposed to what im doing now is the entire workspace is a git repository
3
Answers
Since you are working on two entirely different projects, it is always preferred to have separate
.gitignore
files. The reasons for the same are:-In my opinion, you should go for separate repositories approach.
Also, VS Code workspace currently doesn’t provide any feature of including separate files in a workspace, as it maintains an array of folders only.
Hope it helps!
This is unfortunately not yet supported in the
Visual Studio Code
even though the community has made a request almost 5 years ago. By community has made a request I mean that the issue was actually opened by a Microsoft employee, but was hugely backed by the community.However, it is possible to include a directory in which the files you want to see in the Explorer view are located, but then it is also needed to exclude all the files and directories located in the included directory that you don’t want to see in the
Explorer
view.The drawback of this solution is that I haven’t found a way to position the files in the VSC workspace root, but you can provide a name for the directory in which the files will appear in the VSC Explorer (in the example below it is
my_custom_name
). If thename
attribute is not defined, then the files will be positioned in the directory that is named like the one on the disk in which they are located.To achieve that for your example,
my_app_workspace.code-workspace
should have the following content:Filesystem view:
Visual Studio Code Explorer view:
Yes, you can add individual files to the VS Code workspace by specifying the file path in the "path" field of the "folders" array in the workspace file. For example, you can add the .gitignore and my_app_workspace.code-workspace files by adding the following to the "folders" array:
This will allow you to easily make modifications to these files within the VS Code editor.
As for whether you should split these up into two different repositories in Git, it depends on your use case and workflow. If you want to version control each project separately and have separate .gitignore files for each, then it would make sense to split them into two different repositories. However, if you want to version control the entire workspace as a single unit and have a single .gitignore file for the entire workspace, then keeping them in a single repository would be appropriate.