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

  1. Configure your .gitignore manually or generate one at https://www.gitignore.io/.

  2. Commit your .gitignore file.

  3. Remove the already tracked files/folders from Git cache with:

git rm -r --cached <file-or-directory-to-remove>
  1. Commit the removal:
git commit -m "Remove ignored files from repository"
  1. 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! 👋


Comments

Search

Cargando buscador...