<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd" -->

---
title: Removing a .env file from Git history | daily.dev
description: You accidentally pushed a file with secrets or a password that shouldn&#x27;t have gotten into the Git history. The best thing to do now is to remove the file right...
canonical: https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Removing a .env file from Git history | daily.dev
og:description: You accidentally pushed a file with secrets or a password that shouldn&#x27;t have gotten into the Git history. The best thing to do now is to remove the file right...
og:url: https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd
og:image: https://api.daily.dev/og/posts/B1muMG7Gd_.png
og:image:alt: Removing a .env file from Git history
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Removing a .env file from Git history

**[Hashnode](https://daily.dev/sources/hashnode)** · [@dailydevtips](https://daily.dev/dailydevtips) · 2 min read · 56 upvotes · 11 comments

## Summary

You accidentally pushed a file with secrets or a password that shouldn't have gotten into the Git history. The best thing to do now is to remove the file right away and add it to your .gitignore file. If we look at our Git history, we can still find the file and expose the secrets.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://h.daily-dev-tips.com/removing-a-env-file-from-git-history>

## Community discussion

Top comments from developers on daily.dev.

**@anishde12020** · 2 upvotes

> This was a very useful and interesting article!!! Thanks a lot 😃

**@mheob** · 1 upvotes

> Thanks! This can be very helpful.

**@tracycss** · 1 upvotes

> Thanks learned smth useful about removing files from Git history.

**@tvdheijden** · 1 upvotes

> This is very useful to know, thank you!

**@crypt0** · 1 upvotes

> Interesting!

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#git](https://daily.dev/tags/git)

[View this post on daily.dev](https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Removing a .env file from Git history","url":"https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd"},"datePublished":"2021-11-12T08:05:19.593Z","dateModified":"2021-11-12T08:05:19.593Z","description":"You accidentally pushed a file with secrets or a password that shouldn't have gotten into the Git history. The best thing to do now is to remove the file right...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e9559bc0498dfe2ff2d191a4096e886f","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e9559bc0498dfe2ff2d191a4096e886f","isAccessibleForFree":true,"articleSection":"Hashnode","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Person","name":"Chris Bongers","url":"https://daily.dev/dailydevtips","image":"https://media.daily.dev/image/upload/s--9gxFz1e7--/f_auto/v1705902590/avatars/avatar_JUNiIGCV-?_a=BAMAMiZW0","description":"Daily blogger and web team lead at daily.dev 💖","worksFor":{"@type":"Organization","name":"daily.dev","logo":"https://daily-now-res.cloudinary.com/image/upload/s--MASZOhnv--/f_auto/v1614088267/landing/Daily.dev_logo"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":51595}},"commentCount":11,"discussionUrl":"https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":56},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":11}],"keywords":"git","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Hashnode","item":"https://daily.dev/sources/hashnode"},{"@type":"ListItem","position":3,"name":"Removing a .env file from Git history"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/removing-a-env-file-from-git-history-b1mumg7gd","comment":[{"@type":"Comment","text":"This was a very useful and interesting article!!! Thanks a lot 😃","datePublished":"2021-11-18T05:03:24.945Z","url":"https://daily.dev/posts/B1muMG7Gd_#c-WhnNLy5qv","author":{"@type":"Person","name":"Anish De","url":"https://daily.dev/anishde12020","image":"https://media.daily.dev/image/upload/f_auto/v1641207164/avatars/LmuwH7rcP"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"Thanks! This can be very helpful.","datePublished":"2021-11-13T08:00:04.042Z","url":"https://daily.dev/posts/B1muMG7Gd_#c-51NxffFEy","author":{"@type":"Person","name":"Alex Böhm","url":"https://daily.dev/mheob","image":"https://avatars3.githubusercontent.com/u/3983539?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Thanks learned smth useful about removing files from Git history.","datePublished":"2021-11-22T13:13:48.214Z","url":"https://daily.dev/posts/B1muMG7Gd_#c-5nPlLym4U","author":{"@type":"Person","name":"Jane Tracy Muthoni","url":"https://daily.dev/tracycss","image":"https://avatars3.githubusercontent.com/u/54930887?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"This is very useful to know, thank you!","datePublished":"2021-11-12T10:12:46.124Z","url":"https://daily.dev/posts/B1muMG7Gd_#c-usHxnCcNk","author":{"@type":"Person","name":"Tessa van der Heijden","url":"https://daily.dev/tvdheijden","image":"https://media.daily.dev/image/upload/s--efFpmmNm--/f_auto/v1705569455/avatars/avatar_bu452DQxxXbGcj178k2RJ"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}},{"@type":"Comment","text":"Interesting!","datePublished":"2021-11-12T08:10:49.475Z","url":"https://daily.dev/posts/B1muMG7Gd_#c-tkM6oBDoy","author":{"@type":"Person","name":"Aleksandar Cvjetan","url":"https://daily.dev/crypt0","image":"https://avatars.githubusercontent.com/u/31933549?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}]}
```

