.Net, Azure and occasionally gamedev

Mklink and git submodules


Git submodules make it easy to link specific versions of dependencies into projects without commiting the dependency into the repository - really helpful when using large (and/or binary) dependencies.

The submodule is its own git repository that is linked in (by having the parent project point to the specific commit of the submodule).

This allows you to keep two separate histories while still linking together repositories.

For my homeapp I have split the various projects into separate repositories (app, web, hub and shared).

Normally when you have internal shared logic in .Net the established solution is to create nuget packages and using Azure DevOps makes that very easy (with its built support for custom nuget feeds).

However, I decided against using a custom nuget feed for the homeapp as I want to put the code on github eventually.

My custom nuget feed wouldn't be accessible by anyone but me and I didn't want to publish my internal shared logic to the official nuget feed either.

Instead I opted to put my shared logic into a separate repository (shared) and link it into my 3 actual projects (app, web and hub) via the git submodule feature.

With the shared submodule being checked out three times my workflow now often ended up: checking in changes, pushing to server and pulling the changes back into the other project.

MKlink to the rescue

Since this workflow of constant pushing and pulling can get quite annoying I used the mklink tool to actually link the submodules.

On disk I have checked out these 6 git repositories:

I then ran the following command in app and hub project from a commandline (mklink is not available from inside powershell):

rmdir HomeApp.Shared /S /Q
mklink /J HomeApp.Shared %web%\HomeApp.Shared
cd .git\modules
rmdir shared /S /Q
mklink /J shared %web%\.git\modules\shared

where %web% is the path to the HomeApp.Web git repository.

I essentially deleted two instances of the shared module and replaced it with symbolic links pointing to the third instance.

Anytime I make changes to it the changes are immediately reflected in all 3 parent projects, saving me from having to constantly push & pull to have the changes reflected everywhere!

tagged as Git and Windows