Git - Updating the Repository after changing the Gitignore file

Over the course of working with a Git repository you will likely find the need to add files to the gitignore file. These files might already be tracked in the repository.

To stop tracking these files we need to perform two actions: remove all files from the repository, then re-add them to the repository (which will read from the gitignore). To do this follow these steps:

  • Make any required additions to your gitignore file
  • Commit the changes to the gitignore file only.
  • Ensure you have Git installed on your system ()
  • Open a windows command prompt (cmd)
  • Run the command cd "[path to your local repository]"
  • Execute the following command "git rm -r --cached ."
  • Execute the following command "git add ."

The last two steps remove all the tracked files from the git repository then add them back in again (while obeying any rules stipulated in the gitignore).

Note: pay attention to the period at the end of the git commands.