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

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.


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

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