There are certain situations when you unknowingly add files to git and you try to remove those files later on by adding the names to .gitignore. Even though you add the name of the files in .gitignore, git will continue to track those files even if they were added to the .gitignore later on.
To remove the files/folders from git staging area, you can simply use the following code inside the terminal
git rm --cached file_name
If you are unsure about the filenames, you can use the following lines to do everything up to date.
git rm -r —cached .
After doing those changes, don’t forget to commit the changes otherwise git will not stop tracking those files even if you add those names to the .gitignore later on.