.gitignore for visual studio project is not working
The files are modified, meaning they were already in the git repository before you added the .gitignore file (or you added them explicitly) so you cannot 'ignore' changes to them anymore now.
If possible, just start over again and create the repository from scratch but now make a first commit which just adds the .gitignore file (which is always a good idea btw), then a second commit adding all source files; the build files will then be ignored.
Alternatively you could rewrite the history using interactive rebasing, by modifying the commit in which you add those files, and adding the .gitignore in an earlier commit would also not be bad. Or you could use branch filtering to get rid of all traces of those files. And there's probably other options.
It is possible to stop tracking any changes for any checked in file. You need to tell git to remove the file from its index first by calling the following in the given repository > git rm --cached <file>
. Then update your .gitignore
file to exclude the file. Finally commit the removal of the file.
Source from Microsoft Git guide.
For us worked this approach:
- Check .gitignore file - seemed ok (bin/Debug folder content ignored)
- Check GIT repo for these files (bin/Debug folder content) - they were there => inconsistence with ignore file
- Locally delete these files and commit and push (narrow the GIT files with .gitignore definitions)
- (Optional) Restart Visual studio and perform Pull
- Repository and VS seems now to be in consistent state
To stop tracking the files in the gitignore file;
Open a command prompt and navigate to the directory that contains your solution file (.sln), then run the following commands (first two commands contains dot at last):
- Remove all of the items from the Git index (not from the working directory or local repository):
git rm -r --cached .
- Update the Git index according to gitignore:
git add .
- Commit changes:
git commit -am "Remove ignored files"
Then open your Visual Studio and sync your repo. That seemed to do the trick for me. I found the git commands here.