Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
remove env file from git history
echo '.env' >> .gitignore
git rm -r --cached .env
git add .gitignore
git commit -m 'untracking .env'
git push origin master
@RichardLindhout

This comment has been minimized.

Copy link

@RichardLindhout RichardLindhout commented Jun 5, 2020

This only removes in the most recent unpushed commit not from your whole history

@RichardLindhout

This comment has been minimized.

Copy link

@RichardLindhout RichardLindhout commented Jun 5, 2020

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD
git push --force
@RichardLindhout

This comment has been minimized.

Copy link

@RichardLindhout RichardLindhout commented Jun 5, 2020

Above works also for history

@ItsCosmas

This comment has been minimized.

Copy link

@ItsCosmas ItsCosmas commented Aug 28, 2020

Thanks, this worked for me

@KristenLeach

This comment has been minimized.

Copy link

@KristenLeach KristenLeach commented Sep 2, 2020

I remember needing to do this a long time ago and the instructions I found laid out SUCH a process... thanks for this tip, quick and easy.

@Mupati

This comment has been minimized.

Copy link

@Mupati Mupati commented Sep 29, 2020

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD
git push --force

I just run this and ended up with this error in my CI Pipeline fatal: empty ident name. Anyway to go about it?

@dobpp

This comment has been minimized.

Copy link

@dobpp dobpp commented Nov 13, 2020

It's really handy!

@jbakker87

This comment has been minimized.

Copy link

@jbakker87 jbakker87 commented Dec 8, 2020

for me this was the perfect solution! I always ended up modifying the .env between MAC and WIN. Thanks a lot

@RichardLindhout

This comment has been minimized.

Copy link

@RichardLindhout RichardLindhout commented Apr 28, 2021

Only this worked for me because I came across the same issue
https://stackoverflow.com/a/55017549/2508481

@bryanakitchen

This comment has been minimized.

Copy link

@bryanakitchen bryanakitchen commented May 21, 2021

Perfect! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment