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

C#.NetVisual StudioGitGitignore

C# Problem Overview


I have a C# Visual Studio project in a git repository. I want to ignore the contents bin/Debug directory but not the contents of the bin/Release' directory. I've added bin/Debug to my .gitignore file, but it doesn't seem to work - it is including the entire contents of the bin directory. What would the correct entry be to do this?

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

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

Solution 3 - C#

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:

Solution 4 - C#

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.

Solution 5 - C#

I know it is an old question, but I've decided to share my approach which excludes exactly bin/Debug, bin/Release etc.

*/**/bin/Debug
*/**/bin/Release
*/**/obj/Debug
*/**/obj/Release

Solution 6 - C#

This works for me:

*.exe
*.pdb
*.manifest
*.cache

If you are using GitHub Desktop as I am using it, you can just right click the file you want to exclude or right click it and exclude by extension:

enter image description here

This will automatically generate a .gitignore file for you with the code like above. You can download GitHub Desktop here: GitHub Desktop for Windows 64-bit.

Solution 7 - C#

I fixed this by replacing bin/Debug with Debug.

This would also have the affect of ignoring the obj/Debug directory, however I want to ignore the entire contents of the obj directory, so I have also added obj to .gitignore.

Solution 8 - C#

This may be slightly off topic, but whenever starting to create a new project, I usually use GitIgnore.IO for creating my initial gitignore file and then I tweek it from there according to my needs.

Solution 9 - C#

Right click on those file names you want to ignore from "Git Desktop", then add them to .gitignore file. Here gitignore file will be automatically created. Check in that file to git.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDan StevensView Question on Stackoverflow
Solution 1 - C#orourkeddView Answer on Stackoverflow
Solution 2 - C#Gary.SView Answer on Stackoverflow
Solution 3 - C#NoahView Answer on Stackoverflow
Solution 4 - C#Benjamin RAIBAUDView Answer on Stackoverflow
Solution 5 - C#Evgeny ShmanevView Answer on Stackoverflow
Solution 6 - C#Willy David JrView Answer on Stackoverflow
Solution 7 - C#Dan StevensView Answer on Stackoverflow
Solution 8 - C#FaraxView Answer on Stackoverflow
Solution 9 - C#KiritiView Answer on Stackoverflow