DEV Community

ariburaco
ariburaco

Posted on • Originally published at mystickynotes.net

Removing sensitive data from Git history

Hello folks, this will be a quick but really handy post. Let's say we are working on a side project that we didn't care the sensitive data like credentials of API keys and we want to make the repo public on Github.

I've found a great tool to clear all the commit history of the specific file, in my case it was .env.example.

The tool is called git-filter-repo and it is developed with python.

So, to use the library, first we need to install the python script using:

pip install git-filter-repo

and then we are running this code to delete all the history of the selected file:

git filter-branch --force --index-filter "git rm --cached --ignore-unmatch <the path of file that you want delete>" --prune-empty --tag-name-filter cat -- --all

When you run the code, you will see the remote branch and local are different. Now, you just need to push your local changes with this command:

git push origin --force --all

That's it! Now, when you check the Github, you wont't see any history about that file.

Hope this will help someone having the same issue.

`

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay