---
title: "Discussion on \"Removing a .env file from Git history\" | Hashnode"
description: "Discussion on \"Removing a .env file from Git history\". I'm sure this happens to everyone sometimes. You accidentally pushed a file with secrets or a password that shouldn't have gotten into the Git history.\nIn the following example, I \"accidentally\" pushed my .env file to Git simply because I forgot to a..."
url: "https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Removing a .env file from Git history](https://h.daily-dev-tips.com/removing-a-env-file-from-git-history?utm_source=hashnode&utm_medium=feed)

I'm sure this happens to everyone sometimes. You accidentally pushed a file with secrets or a password that shouldn't have gotten into the Git history. In the following example, I "accidentally" pushed my .env file to Git simply because I forgot to a...

Nov 10, 2021 · 2 min read · h.daily-dev-tips.com  
Read the article

-   [#github](https://hashnode.com/tag/github)
-   [#git](https://hashnode.com/tag/git)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Chris Bongers](https://hashnode.com/@dailydevtips)

@dailydevtips · Cape Town, SA

  
[View profile](https://hashnode.com/@dailydevtips)

Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.

## Responses 4

Markdown supported · ⌘↵ to post

[Jimmie Butler](https://hashnode.com/@jimmie)

[Nov 16, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/61938d0941b5ce67583af0f5)

What's the point in doing this? Regardless of what's in git, the credentials need revoked and git-ignored to prevent in the future. Removing from git history is some extra steps that doesn't really do anything.

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Nov 16, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/61938d0941b5ce67583af0f5#reply-61938e20095c0c66c77f5507)

Hey Jimmie,

I just like clean repo's. And like I said the env is more a demonstration of a common example.

It might have been another file you wish to remove from the history all together.

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Nov 14, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/619121a083e4212d6e579b6e)

Thanks for sharing this. Will be handy someday 😀

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Nov 14, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/619121a083e4212d6e579b6e#reply-61914dc5770afc563f6678da)

Haha, I hope you never have to use it. But that day you do, it's here for you 👋

[Ayodele Samuel Adebayo](https://hashnode.com/@unclebigbay)

[Nov 14, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/619121a083e4212d6e579b6e#reply-61917bc2770afc563f667b27)

😂 [Chris Bongers](https://hashnode.com/@dailydevtips).

I've made the mistake once, while I was writing an article and pushing the code to GitHub, I revoked the Key but didn't know about this solution.

This will come in handy when someone else asked me or a colleague makes the mistake.

It's just so nice to know this things exist on your blog 😂

[James 'Dante' Midzi](https://hashnode.com/@Psypher1)

[Nov 11, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/618ca17c468c06249afc72e4)

I had to do this a couple of days back. Thank you for this

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Nov 11, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/618ca17c468c06249afc72e4#reply-618ca35ef991b025366e2097)

Happens to everyone.

I've added a small subnote: If you accidentally pushed real-world secrets to a repo, you should always revoke and regenerate them.

[James 'Dante' Midzi](https://hashnode.com/@Psypher1)

[Nov 11, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/618ca17c468c06249afc72e4#reply-618ca56c468c06249afc733f)

Thanks for that, I will definitely keep that in mind.

[Vishwajeet Raj](https://hashnode.com/@vishwajeetraj11)

[Nov 11, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/618c707c468c06249afc705d)

This is gold, thanks for sharing.

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Nov 11, 2021](https://hashnode.com/posts/removing-a-env-file-from-git-history/618b5c6c468c06249afc5a33/comment/618c707c468c06249afc705d#reply-618ca324468c06249afc7310)

Glad you like it Vishwajeet! 🎉
