Write a .gitignore for a Visual Studio project
Ignore Visual Studio build output and user state while keeping solution files, project definitions, and intentional shared editor configuration.
Start with the maintained VisualStudio.gitignore template and adapt it to your project. The main exclusions are generated output, per-user IDE state, and restorable caches. Keep the files that define how someone else builds and works on the project.
Common rules
This compact starting point covers typical .NET projects:
# Build output
[Bb]in/
[Oo]bj/
[Oo]ut/
[Dd]ebug/
[Rr]elease/
x64/
x86/
# Visual Studio user state
.vs/
*.user
*.suo
*.userosscache
*.sln.docstates
# Generated symbols, profiling output, and test results
*.pdb
*.psess
*.vsp
[Tt]est[Rr]esults/
# Generated NuGet packages
*.nupkg
*.snupkg
# Per-user ReSharper settings
*.DotSettings.user
Check broad patterns such as x64/, x86/, and *.pdb against your actual layout. If your project intentionally versions a file with one of these names, narrow the rule. Store release symbols as build artifacts when appropriate rather than mixing them with source.
What the rules protect against
.vs/ contains local Visual Studio state, while .suo and .user files can hold personal debugging and workspace settings. Sharing these often creates irrelevant changes or exposes machine-specific values.
Bracket patterns such as [Bb]in/ explicitly cover both spellings. Matching behavior can also be affected by the environment and Git configuration, so test actual paths rather than relying on filesystem case behavior alone.
For older packages.config projects, package restore can recreate downloaded package contents. The full template includes exceptions such as a packages/build/ directory that may contain required MSBuild targets; blindly ignoring every packages/ directory can hide those inputs. Modern PackageReference projects normally use a global packages cache outside the repository. Keep dependency declarations and any lockfiles required by your team's restore policy.
Use the full template where needed
The full template covers many project families and tools, including database projects, profiling, and additional build systems. Review the relevant sections instead of assuming a short generic list covers every project.
For teams using VS Code or Rider alongside Visual Studio, decide which editor settings are shared. The maintained Visual Studio template has selective VS Code exceptions; it does not mean every .vscode file should be discarded. Do not add a blanket .idea/ exclusion if the team intentionally versions selected Rider settings. Commit a shared .editorconfig when it defines your coding conventions.
FAQ
What if bin or obj is already tracked?
For root-level directories:
git rm -r --cached -- bin obj
git add .gitignore
git commit -m "Stop tracking build output"
Adjust the paths for each project. This retains the current local files and removes them from future snapshots, but earlier commits still contain them. Historical size reduction requires a separate coordinated cleanup.
Should solution and project files be committed?
Yes: files such as .sln, .slnx, and .csproj describe the solution and project. Keep the definitions your project actually uses. The exclusions target personal state and generated output, not the build's source configuration.
Is one template enough for a mixed-editor team?
It can be, after review. Combine project-wide build exclusions with explicit decisions about shared editor configuration. Personal preferences can go in each developer's global excludes file instead of expanding the team's ignore rules unnecessarily.
See VisualStudio.gitignore, gitignore, and git-rm.
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan