'gitignore doesn't ignore .suo Visual studio file

I want to do simple thing, ignore .suo file and bin and obj folders from committing to git repo. I've created .gitignore file and it's working for bin and obj folders, but it keeps allowing .suo file committing. The content of gitignore is simple:

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

Firstly I've thought that the problem is that .suo file is already on the repo, so I've used set of git commands to remove it from repo:

git rm "file.suo"
git commit -m "suo removed"
git pull origin master
git push origin master

And everything goes well, .suo is removed locally, it is removed from repo, and on the next commit it gets pushed again to repo.

On the picture is committed .suo file.

enter image description here

Did anyone had a problem like this? How to solve this kind of problem?



Solution 1:[1]

This is probably a duplicate of GIT - Can't ignore .suo file

And to be honest, you can try that suggestion. What you are missing here is to remove the already added *.suo file from the git repository.

The other answer has a nice set of commands to run:

git rm --cached *.suo
git commit -m "Delete suo file from repository"

Solution 2:[2]

Jsper answered correct. He already explained why this usually happens. But I got another probably easy solution without command line & gui lover devs. What I simply do is:

  1. First delete the directory or file from your github/dev ops repository from web gui
  2. Then simply sync your project locally first then you are ready to make new commit without your annoying autogenerated file or directory.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Liakat Hossain