Sometimes, your .gitignore suddenly stops working as in even though you have added files and folder in it, they are not actually being ignored by git and is still getting tracked.
it might happen due to you have added the .gitignore after you added these files(That are not being ignored) to the repo.
it happens because, the files are already added to the repo before it could be ignored as .gitignore was created after the actual files in the repo.
Note that, The files/folder in your repository will not be deleted just because you added them to the .gitignore. They are already in the repository and you have to remove them manually.
You can just do that by following these steps:
-
Open Terminal in the Repo directory.
-
commit everything you've changed till now.
-
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system, run this command in your terminal:
git rm --cached filename
OR
-
To untrack every file that is now in your .gitignore, run this command in your terminal:
git rm -rf --cached .
This removes any changed files from the index(staging area). -
Then run this command
git add .
-
Commit it by:
git commit -m ".gitignore fixed, removed ignored files"
This is my first gist and it written just to check gist out
Reference: Git-Docs, Stackoverflow