Visual Studio
.gitignore
Coding
Programming Projects
Version Control

.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/ and obj/
  • user-specific settings such as *.user and *.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:

gitignore
1# Visual Studio workspace metadata
2.vs/
3*.suo
4*.user
5*.userosscache
6*.sln.docstates
7
8# Build output
9[Bb]in/
10[Oo]bj/
11[Dd]ebug/
12[Rr]elease/
13x64/
14x86/
15
16# Test results
17TestResults/
18*.trx
19*.coverage
20
21# Logs and temporary files
22*.log
23*.tmp
24
25# NuGet package folders for older packages.config workflows
26packages/
27
28# Rider or VS Code metadata if the team does not track it
29.idea/
30.vscode/

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:

bash
git rm -r --cached .vs bin obj
git commit -m "Stop tracking generated Visual Studio files"

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.


Course
Intermediate
27 lessons
14 hours
OOD Fundamentals

Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.

View the course
Data 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.

Practice algorithms