Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to commit .env files into the repository?

I have just started learning backend dev using django. My question is do I just commit the project files in the server folder alone, or should I also commit the .env folder to the repository?

I have done the following:

  1. I have created virtual environment and I have also installed django in venv.
  2. I have setup a django server and super admin.
  3. I have setup the config.json to protect my API key.
  4. Included the same in .gitignore.

What happens if I do or do not commit .env?

like image 822
Sridhar Murali Avatar asked Jun 26 '19 04:06

Sridhar Murali


People also ask

Should .env files be committed?

env files to version control (carefully) Many software projects require sensitive data which shouldn't be committed to version control. You don't want Bad Guys to read your usernames, passwords, API keys, etc.

Should I commit .env file react?

No you don't. . env file should be put on server in a separated way. Otherwise whoever can access to your source code repository can read or even modify .

Where do I put the .env file?

env file is placed at the base of the project directory. Project directory can be explicitly defined with the --file option or COMPOSE_FILE environment variable.

Should I Gitignore .env files?

The short answer is, “yes”. You should use your . gitignore file to ignore the . env file.


1 Answers

Assuming that your .env folder is your virtual environment, no you should not commit it.

The virtual environment should be rebuilt on the server using your requirements.txt file. The local environment you built on your development machine may have operating system specific binaries, and other compiled code that was generated for your local environment.

The server will have different compiled binaries, and therefore should rebuild the virtual environment using: pip install -r requirements.txt.

like image 89
damon Avatar answered Nov 07 '22 15:11

damon