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
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.
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.