Accidently uploaded .env file to GitHub?  Here's a solution...

Accidently uploaded .env file to GitHub? Here's a solution...

How often it happens to us that we forgot to add the .env file in our .gitignore file and end up publishing our sensitive data like API keys to the GitHub repository.

If you have done something similar and are finding a way to remove it from there, here are a few steps that you can follow.

In your terminal where you have that repository locally on your computer, you need to type the following commands and you are good to go.

STEP 1: Firstly we need to untrack the .env file from git using

 git rm --cached .env

STEP 2: Then add the changes to the staging area using

git add .

STEP 3: Then we need to commit our changes locally

git commit -m "your-message-here"

STEP 4: Lastly we need to push the changes to our remote repository using

git push -u origin master

<--- here master is the name of the branch make sure to check your branch name -->

After following all these steps you will see that the .env file will be removed from the GitHub repository.

Next time make sure to add the .env file to the .gitignore beforehand.

Hope you find this helpful, if so please like it.