# Visual Studio out of tree build tree and .git directory

**URL:** https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413
**Category:** Usage
**Created:** [December 20, 2025, 1:45am UTC](https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413 "2025-12-20T01:45:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Hunter](https://discourse.cmake.org/user_avatar/discourse.cmake.org/david_hunter/32/115_2.png) [@David\_Hunter](https://discourse.cmake.org/u/David_Hunter)
#### Post date: [December 20, 2025, 1:45am UTC](https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413/1 "2025-12-20T01:45:22Z")

</div>

I generate a Visual Studio project out of tree in some `build` directory from some `source` directory. The project uses Git so the `source` directory has a `.git` directory.  
If I open the resultant Visual Studio solution it does not think the project is using Git. This is because it expects a `.git` directory in the `build` tree.  
At present I have some generate time CMakeLists.txt stuff that checks the `source` tree for a `.git` directory and does a `mklink` in the `build` tree to create a symlink from the `build` directory to the `source` `.git` directory and things work fine when I open Visual Studio.

I am wondering if there is a better way to do this. Maybe built into CMake or there is some stuff I can get output into the generated `MSBuild`which can tell Visual Studio where the `.git` directory is.

There may be an issue for other generators but I’m only interested in Visual Studio.

---

<div class="post-metadata">

### Author: ![Andrej730](https://discourse.cmake.org/user_avatar/discourse.cmake.org/andrej730/32/5752_2.png) [@Andrej730](https://discourse.cmake.org/u/Andrej730)
#### Post date: [December 20, 2025, 6:08am UTC](https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413/2 "2025-12-20T06:08:19Z")

</div>

It sounds odd that Visual Studio requires for the project to be rooted next to `.git`, since it’s almost never the case - even projects that maintain VS projects directly, without cmake, are typically having it in some subfolder, either because Windows is not the only available platform or because they need multiple projects (e.g. different ones for different VS versions).

And it’s very simple to to check whether folder is part of git repository - almost any `git` command can do that or `git rev-parse --show-toplevel` can show the root folder. So there must be some setting in Visual Studio that allows to search for git repository not just at the solution root.

---

<div class="post-metadata">

### Author: ![JRR](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ecccb3/32.png) [@JRR](https://discourse.cmake.org/u/JRR)
#### Post date: [December 23, 2025, 3:44pm UTC](https://discourse.cmake.org/t/visual-studio-out-of-tree-build-tree-and-git-directory/15413/3 "2025-12-23T15:44:07Z")

</div>

I agree with @Andrej730, this feels like a layout challenge or maybe `Visual Studio` configuration item.

Our company has multi-platform projects using VS2017, VS2019, VS2022 on Windows and stock `gcc` on Ubuntu, Fedora and Rocky Linux platforms.

The rough general file hierarchy we have:

```auto
<repo-root>
├───.git
├───Build ........................<generated>
│ └───build64 ..................<generated>
│ └───VS2022 ...............<generated>
│ └───project.sln ......<generated>
├───CmakeLists.txt ...... <top-level>
└───source

```

Following up on @Andrej730‘s suggestions/questions. Is your **build** folder in the repository? For example, if you used Windows CMD shell to navigate to be in the folder that your `.sln` file lives and invoked the command `git status`, what happens?

If it says it’s not inside a **.git** repository then that’s your problem, you would need to move the build folder to be outside the source but still under root folder for the repository.

In my experience, the build folder does not need to be _ **managed** _ by the repository but it needs to be _ **under** _ repository’s root folder. You can use the `.gitignore` file to instruct git to ignore everything under the **build** folder so it does not appear in your `git stats`, `git diff` `git add -u`, etc. commands.
