How to clear git cache


Let’s start with, How to clear git cache. When we are managing our code using GIT. Some times we forgot to add files on the git ignore file. We realised that after pushing the code on Git server and we add those files on git ignore file.

However, when we are pushing the code we realised some of the files are still showing even we added on the Git Ignore file. In this case, You may need to remove the Git cache.

How to clear git cache

1 ) Entire Git

We are going to clear entier git cache by following the commands.

git rm -r --cached .
git add .
git commit -am 'git cache cleared'
git push origin branch_name

It will remove all files listed on the gitignore file from the repository.

2 ) Specific file

We are going to remove specific files cache from the git repository instead of the entire cache.

git rm --cached database.php
git add --all
git commit -m "Remove the database config file cache"
git push origin branch_name

In this tutorial, you learn how to remove gitignore files from git repository and it will help when you update the .gitignore file.

I hope this article useful for you. Please let us know if anything was missing or wrong by comment.


Leave A Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.