Is it possible to share a single file in the root folder of multiple git repositories?

Viewed 729

Our team has multiple repositories for code and we're looking into ways to get a single location for some shared config files (specifically, the .editorconfig file).

Is there a way to share a single file, AT THE ROOT OF A GIT REPOSITORY, across multiple repositories? Is there any other ways that someone knows of, that don't involve having some script that "downloads" the same version of the file? Thanks a lot for any help, in advance.

Cheers

2 Answers

You can't have a shared file among multiple repositories. However, editors should search up the directory hierarchy for an .editorconfig file, so if you have a directory in which all of your existing repositories live, you can install it in that directory, and it will apply to all repositories.

One way of doing this is to provide a repository which contains the .editorconfig and any other relevant development code, and checking out other code underneath it. GitLab uses this for their development environments.

I've defined next way:

  1. Create a NuGet package with .editorconfig file inside.
  2. Add this into the NuGet package .csproj file.
<ItemGroup>
  <None Update=".editorconfig">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>
  1. Add a reference or install your NuGet pakcage into your project where you want to import your .editorconfig.
  2. Then add this target to the project.
<Target Name="CopyFile" AfterTargets="AfterBuild">
    <Copy SourceFiles="$(OutDir)/.editorconfig" DestinationFolder="./" />
</Target>

  1. Build your project and the .editorconfig will appear in the root of your project.

I believe there is a possibility to modify the .csproj file during NuGet package installing process. If it is true, then step 4 could be authomated.

Related