visual-studio

Where should I run git init in a Visual Studio 2022 project with nested folders?


I want to introduce Git into my Visual Studio 2022 project, but where exactly should I place the .git directory (i.e., where should I run git init)?

I created a project called MyTestApp, but for some reason it was created in a nested structure like repos/MyTestApp and repos/MyTestApp/MyTestApp. I’m not sure which of these directories should have the .git repository.

This output was generated by running tree /F /A > filelist.txt in the terminal under "C:\Users\lapislazuli\source":

C:.
|   filelist.txt
|   
\---repos
    +---MyTestApp
        |   MyTestApp.sln
        |   
        \---MyTestApp
            |   App.config
            |   Form1.cs
            |   Form1.Designer.cs
            |   MyTestApp.csproj
            |   Program.cs
            |   
            +---bin
            |   \---Debug
            +---obj
            |   \---Debug
            |       |   .NETFramework,Version=v4.8.AssemblyAttributes.cs
            |       |   DesignTimeResolveAssemblyReferences.cache
            |       |   DesignTimeResolveAssemblyReferencesInput.cache
            |       |   MyTestApp.csproj.AssemblyReference.cache
            |       |   
            |       \---TempPE
            \---Properties
                    AssemblyInfo.cs
                    Resources.Designer.cs
                    Resources.resx
                    Settings.Designer.cs
                    Settings.settings
                    

Exact steps I followed

  1. Double-click the Visual Studio icon on the taskbar to start it.
  2. The Visual Studio Installer window appears.
  3. Click [Launch] for Visual Studio Community 2022.
  4. The Visual Studio 2022 window appears.
  5. Click [Create a new project].
  6. Select [Windows Forms App (.NET Framework)].
  7. Click [Next].
  8. Click [Create] with the following settings:
    • Project name: MyTestApp
    • Location: C:\Users\lapislazuli\source\repos
    • Solution name: MyTestApp
    • “Place solution and project in the same directory” → unchecked
    • Framework: .NET Framework 4.8

When I checked “Place solution and project in the same directory”, the nested structure did not occur. However, I’m not sure if that’s the correct approach.


Solution

  • Just create version control system here, the solution file also need to be tracked.

    repos/
    └── MyTestApp/              <-- .git folder here
        ├── .git/
        ├── .gitignore
        ├── MyTestApp.sln
        └── MyTestApp/
            ├── MyTestApp.csproj
            ├── Form1.cs
            └── ...
    

    The nested folder structure is quite common. I don’t use Visual Studio myself, but in VS Code, it also defaults to creating a nested setup, with the project files in a subfolder and the solution file located at the root of the workspace.

    VS Code Example