How could I ignore bin and obj folders from git repository?

I want to ignore bin and obj folders from my git repository. As I've found out, there is no easy way to do this in .gitignore. So, are there any other way? Using clean solution in Visual Studio?


Solution 1:

I'm not sure why this doesn't work for you. In case it helps, here's a typical .gitignore file from one of my Visual Studio/git projects:

*.suo
*.user
_ReSharper.*
bin
obj
packages

Solution 2:

simply making an entry in gitignore may not ignore files, you may need to commit it. I used the following method and worked for me

git rm -r --cached .

git add .

then

git commit -am "Remove ignored files"

However, this ignores my scripts folder which I included later into the repository.

Solution 3:

Update

After a recent update of Visual Studio 2019, the below option was not available. Alternatively, you can also copy the latest gitignore content from the below location. https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore

Original Answer

If you are using Visual Studio then there is a simple way to do this.

  1. Open Team Explorer
  2. Click on settings
  3. Repository Settings
  4. Under Ignore & Attribute file section Click on Add beside Ignore file.

It will create a default .gitignore file, which will ignore most of the common folders & files that will be used by the framework/language.

enter image description here

Solution 4:

If you have committed the bin and obj folders previously, adding them to .gitignore will not automatically delete them. You need to commit deleting these folders with for example git rm -rf obj or git rm -rf yourProject/obj then commit the deletion