.gitignore and Visual Studio project: Ignore bin/Debug directory but not bin/Release directory

You shouldn't have to delete anything. After you added the .gitignore file, run this command to clear the cache, then stage and commit again:

git rm -r . --cached

This typically happens because the .gitignore was added after the files were committed. The .gitignore tells git to ignore untracked files that match, once stuff is committed the ignore will no longer work. One way to fix it is to remove the bin/debug folder (manually through explorer/powershell/bash), then commit the removals. Once that is done the ignores should work as you expect.

  1. Remove files/folder
  2. git add -A
  3. git commit

Here's what we've been using lately, it removes all resharper generated stuff and some other important things. Note that we don't commit our release directory, so you shouldn't include Release/ in your .gitignore, but to answer your question, you should include Debug/.

/build/
*.suo
*.user
_ReSharper.*/
*.sdf
bin/
obj/
Debug/
Release/
*.opensdf
*.tlog
*.log
TestResult.xml
*.VisualState.xml
Version.cs
Version.h
Version.cpp

UPDATE

Here's a pretty comprehensive example from github:

  • https://github.com/github/gitignore
  • https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

Running the following command worked for me (thanks to "orourkedd"):

git rm -r . --cached

I manually added the .gitignore file but it wasn't taken into consideration until I ran this command.

I then had to commit again and all good to go now. /bin and /obj folders are properly excluded now.