How to refresh or reread gitignore file

Shegun Babs
Shegun Babs Thu May 2018

If you have a local git repository installed from frameworks such as Laravel, React, Nextjs etc. chances are that you already have a .gitignore file bundled with your local repository.

If by chance you add a new file or directory or your IDE adds a directory (most IDEs do this) and you don't want git to track the file or directory, you just add the file or directory to the .gitignore file.

git will continue to track the file or folder path newly added to .gitignore until we "refresh" .gitignore

What to do after making new changes to a .gitignore file

  1. Make the changes to the .gitignore file
  2. Run git rm -r --cached . command. This removes all files recursively from the version control but it can still be tracked in the repository.
  3. Run git add . all (include updates to all files in the next commit)
  4. Commit all changes - git commit -m "commit message here"