#4 – [Git_Filter_Repo] – How to remove the complete file or folder from the GIT repository including history?

Just as what we discussed in our previous post, Complete the setup till Step -3 , and proceed with this post.

  • Once we have completed the fresh clone for the repository.
  • Navigate to the freshly cloned repository and open GitBash terminal.
  • Execute the below command.
git filter-repo --path GitGuardianDemo/src/testtoken.key --invert-paths

Do not miss to add –invert-paths in the above command, if you fail to do so, it will remove all the other files from your repository except the testtoken.key file. (inversion of the above command).

Important Reminder!

We can see in the above commits history that the file itself is not available in the commit versions.

Now Time to PUSH the changes to the remote repository

Execute the below commands in sequence


git push --tags --force https://github.com/vigneshram20/SecretsRemovalTest.git
git push --all --force https://github.com/vigneshram20/SecretsRemovalTest.git

Now we have successfully pushed the changes to the remote repository,

It’s time to check the GITHUB for the reflected changes

As expected, the file testtoken.key is not available in the existing repo and as well as in the commits history.

If you want to remove the entire contents from the particular folder path, use the same command without the filename, it will remove all the files from the given path.

git filter-repo --path GitGuadianDemo/src/ --invert-paths
Vigneshram Sundaramoorthy
Vigneshram Sundaramoorthy

Hello World!
I am a tech enthusiast who believes in smart stuff, working as an SDET , I like to learn, create new approaches, I am someone who strive to think in a different perspective.

Articles: 10

Leave a Reply

Your email address will not be published. Required fields are marked *