.gitignore for Visual Studio projects and solutions
Codemia Knowledge Hub ·
A good Visual Studio .gitignore commits code and project definitions but ignores user-specific settings, build output, caches and generated artifacts that can be recreated. In practice that means ignoring .vs/, bin/, obj/, *.user, *.suo and test output, and keeping .sln and project files.
What Visual Studio generates that does not belong in Git
- build output such as
bin/andobj/ - user-specific settings such as
*.userand*.suo - IDE metadata such as
.vs/ - test output and coverage artifacts
- package restore caches or temporary generated files
These files either vary from machine to machine or change too often to be useful in version control.
A starting .gitignore for C# solutions
This compact file works for many C# and Visual Studio solutions:
Treat it as a baseline. Real projects often need a few additions or removals depending on the stack. Copying a giant template blindly produces a file full of rules that do not match the project, so start from a solid template and trim it.
Files you should keep
Ignoring too much is as harmful as ignoring too little. Keep:
.sln.csproj,.vbproj, or other project files- source code under
*.cs,*.ts,*.js, and similar - configuration that is intentionally shared
- migration files, scripts, and assets required to build the project
If a new teammate cannot clone the repo and build the solution because a necessary file was ignored, the .gitignore is too aggressive. Ignoring all config files, for example, can hide a shared configuration file the application needs.
NuGet in older and SDK-style projects
For older projects that use packages.config, ignoring the local packages/ folder is common because packages can be restored.
For SDK-style projects with modern package restore, you usually still ignore generated package directories and machine-local caches, but you keep the project file that declares the package references. The rule is the same everywhere: keep declarations, ignore recreatable downloads.
Untracking files that were already committed
.gitignore only prevents new untracked files from being added. If bin/ or .vs/ was committed earlier, adding it to .gitignore will not remove it from the repository. Stop tracking it explicitly:
This catches many teams that add a .gitignore after the repository already exists. Committed bin/, obj/ or .vs/ folders create noisy diffs and pointless merge conflicts.
Repository rules versus a global ignore file
Git supports a global ignore file on each developer machine, which is useful for editor backups or OS-specific clutter. Project-specific rules such as .vs/, bin/ and obj/ belong in the repository's own .gitignore so every teammate gets consistent behavior. Keep the global file for personal machine clutter only.
Related reading
- Global keyboard capture in C application
- Global setting for AsNoTracking?
- GO statements blowing up sql execution in .NET
- Good GetHashCode override for List of Foo objects respecting the order
- .gitignore is ignored by Git
- .gitignore is not ignoring directories
- Good introduction to the .NET Reactive Framework
- Good or bad practice for Dialogs in wpf with MVVM?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.