Published on

How to clear your git cache


While working with git you may encounter some issues like some time you add some lines to ignore files/folders in the .gitignore file. but that file still exists in your git. In that case, you might need to clear your git cache.

Let's learn comprehensively how to clear your git cache with different use cases.

The best and easiest way to clear git cache is to use git rm command. there are many options you can play with it based on your use cache. to list option of git rm run git rm --help

we will use --cached option to remove one file or whole working directory.

For example, I need to clear the test.log file then add

# .gitignore file *.log

I have committed that file in earlier commit but after adding in .gitignoer still there. so we use git rm command with --cahed option.

$ git rm --cached test.log

In case you want to clear your entire git cache when you have multiple files at multiple location. then will add one extra option -rmeans recursively clear cache.

$ git rm -r --cached .

When all file remove from cache you can add back to them index in git by below command

$ git add .
$ git commit -m 'Removed cache'
$ git push

Now you know how to clear your git cache. in case you stuck with the index file to be not removed when added in .gitignore file you have the answer.