Categories
Git

Remove Your .env file from your GitHub Repository

If you, just like me, accidentally added the .env file in your GitHub repository, and now tried everything but the .env file changes are still being pushed to your GitHub repository, you can use this tutorial and just remove your .env file being update and synced with your remote origin repository.

To exclude the .env file from being added to your Git repository, you can use the .gitignore file. Here’s how you can do it:

  1. Open your .gitignore file (or create one if it doesn’t exist) in the root directory of your project.
  2. Add the following line to the .gitignore file: .env

This will tell Git to ignore the .env file and prevent it from being tracked or added to the repository.

If you have already added the .env file to your repository, you can remove it from the Git index while keeping it in your local file system with the following command:

git rm --cached .env
Code language: CSS (css)

After running this command, commit the changes:

git commit -m "Remove .env file from tracking"
Code language: JavaScript (javascript)

This will ensure that the .env file is no longer tracked by Git but remains in your local directory.

Would you like more help with Git commands or anything else? Just check our Git learning Path.

By Abdul Rehman

My name is Abdul Rehman and I love to do Reasearch in Embedded Systems, Artificial Intelligence, Computer Vision and Engineering related fields. With 10+ years of experience in Research and Development field in Embedded systems I touched lot of technologies including Web development, and Mobile Application development. Now with the help of Social Presence, I like to share my knowledge and to document everything I learned and still learning.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.