How to Properly Use .gitignore and Remove Already Tracked Files
Git Tips
🧹 How to Properly Use .gitignore
and Remove Already Tracked Files
Good practices say you should configure your .gitignore
before starting your project to keep your repository clean. However, many of us (including me!) often forget to do it initially.
Later on, when your project is already advanced, you might find system folders or unwanted files already committed, and that can be frustrating!
How to fix it when files/folders already tracked by Git are in your repo
-
Configure your
.gitignore
manually or generate one at https://www.gitignore.io/. -
Commit your
.gitignore
file. -
Remove the already tracked files/folders from Git cache with:
git rm -r --cached <file-or-directory-to-remove>
- Commit the removal:
git commit -m "Remove ignored files from repository"
- Push the changes:
git push
Now the files or folders ignored by .gitignore
won’t appear in your repository anymore.
Keep your repo clean and happy! See you next time! 👋