Within a Visual Studio Code workspace you can work with multiple git repositories.

There will be no problem if the git repositories belongs to different directories and some repositories are beneath a parent one.

This will be for example the cache of you work within a PHP project which uses composer to manage its dependencies. In the normal case your project is root is the root of the projects git repository, too. But in some cases you could also work in the same project on some other package which is beneath the vendor directory.

In this case Visual Studio Code cannot handle the package’s git repository and won’t show you diffs etc. in your files. To fix that you have to add the package as a seperate folder into your workspace. This you can simply do by File -> Add Folder to workspace.... Now you select your package and will be shown in your Explorer view. But this will not solve the problem. By default the new folder will be added beneath you project folder. To get the git integration running you have to move the new folder above the project root’s folder in the explorer view. To do that you can simply drag and drop the project root folder in the Explorer view at the end of the list or you can edit the *.code-workspace file of your current workspace you are working on.

I place that workspace file normally beneath the project root to have it in the VCS. If you open that file you will see json code and there the list of your workspace folders inside the folders part. You can also move your project root ({"path": "."}) at the end of that list. If you edit that file you have to reload the window. When using the drag and drop solution you don’t have to do that.

When you now switch to the Source Control view you will see all your git repositories. If not simply click in the three dots at the top right of that view and select Views -> Source Control Repositories.

That’s it.

Categories: Visual Studio Code