When adding a .gitignore to a repository, the files which are already tracked will still be tracked, even though it is excluded in the .gitignore.

This may happen when a .gitignore is added latter or an SDK / Build Tool (like Flutter) updates, adding more components and files.

To implement the newly added .gitignore follow below steps

1) Commit any unsaved changes

2) Open the github repository in command prompt / windows terminal and use below command to removes everything from the index and keeps it in working area (all files are now not tracked by git or untracked)

git rm -r --cached .

3) Now sends all files from the untracked area to the stage area using below command, thus implementing .gitignore afresh

git add .

4) Now commit the changes using below command

git commit -m ".gitignore is now working"

5) Finally push the commit to the remote repository (on github)

git push origin

The last step can also be done on github desktop, where after step (4) commits are ready to be pushed.

Last updated