If your GIT repository is tracking files that you want to ignore (i.e. you init your repo without .gitignore file) then these files still be present in you repository index also after adding them to the just created .gitignore file.
Step 1 – Create (or modify) .gitignore file
If you need an helping hand go to https://www.gitignore.io/ (for csharp https://www.gitignore.io/api/csharp.
Step 2 – Commit all your changes
After .gitignore file has been saved, commit all you files, including your new .gitignore file.
git commit -m “Fixed .gitignore issue.”
Step 3 – Remove everything from the repository
Clear your repo by using:
git rm -r –cached .
where
rm is the remove command
-r will allow recursive removal
–cached will only remove files from the index. Your files will still be there.
The . indicates that all files will be untracked. You can untrack a specific file with git rm –cached foo.txt (thanks @amadeann).
The rm command can be unforgiving. If you wish to try what it does beforehand, add the -n or –dry-run flag to test things out.
Step 4 – Re-Add everything
By using
git add .
Step 5 – Commit
By using
git commit -m “.gitignore fix”
Step 6 – Push
Push the changes to your remote to see the changes effective there as well.
git push
Useful .gitignore template:
Javascript: https://gist.github.com/andreasonny83/b24e38b7772a3ea362d8e8d238d5a7bc