The .gitignore file ensures that files not tracked by Git are left without a trace.
Just adding folders / files to the .gitignore file will not eliminate them - they will be tracked by Git.
To track files, you must remove the tracked files listed in the.gitignore file from the repository. Then add them and make changes.
The easiest, most comprehensive way to do this is to delete and cache all the files in the repository, and then add them back. All folders / files listed in the .gitignore file will not be tracked. In the top folder in the repository, run the following commands:
git rm -r --cached. git add.
Then make your changes:
git commit -m "Untrack files in.gitignore"
Note that any previous commits with unwanted files remain in the commit history. When you click on GitHub, you should know the commit history, which may contain .env or client_secret.json .
The best practice is to create a .gitignore file and populate it with folders / files that you do not want to keep track of when you start the project. However, it is often necessary to add a .gitignore to the file after you know that unwanted files are tracked and saved.
source share