Using Visual Studio with Git
Visual Studio Solutionsbrings in lots of files and folders that don't belong in a checked in repository.
ForHere's checkeda outgood gitignore file for Visual Studio projects, here's a working .gitignore file:projects:
# This works in Visual Studio projects
# to ignore most VS generated output.
# NOTE: It does not work for VSCode.
# Ignore Build results...
**/[Bb]in/*
**/[Oo]bj/*
**/[Ll]og/*
**/[Ll]ogs/*
**/[Tt]emp/*
**/[Tt]mp/*
# Ignore Visual Studio specific...
**/.vs/*
*.user
*.suo
*.userosscache
*.sln.docstates
# Ignore publish folders...
[Pp]ublish/
For Existing Project
If you plan to include the above gitignore in an existing project that was already using explicit ignores, then you may need to do the following to reset the list of tracked files.
- Update the .gitignore file in your working copy with the above content.
- Open a Powershell terminal, and navigate to the root of your working copy.
You may have to quote the folder path, for Powershell to recognize it. - Run this powershell from the checkout root, to untrack all files in Git:
# Remove all tracked bin, obj, .vs, and publish folders git ls-files | Where-Object { $_ -match '\\(bin|obj|\.vs|publish)\\' } | ForEach-Object { git rm -r --cached "$_" } - Then, open a command line window, also in the checkout root, and run this to add your gitignore file and commit the cleanup:
git rm -r --cached . git add . git commit -m "Refresh tracked files with updated .gitignore" - Once that is done, you can