BugHunterUK BugHunterUK - 1 year ago 41
Git Question

Pushing repo with environment variables

In my repo on my machine I have a file called

. This contains environment variables for testing as I'm working on the project.

But, when I push to Github I do not want this file included. So I added it to
. I have another file called
that contains empty variables for the user to set.

When the application is installed using
npm install
I have a script that moves this from

This causes an issue for me because when I'm testing and I run the install it overwrites my original
. Which is normal behaviour, but I can't help but think there's a better way to do this to stop that from happening.

It's a pain because just before I push I have to rename
and clear the development variables.

Any idea on how to do this so I don't have to manually rename the file before I push?

Here is the install script from

"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack --config webpack.config.babel.js",
"start": "npm run build && electron .",
"postinstall": "bash postinstall.sh && mv .env.sample .env",
"add-cors": "add-cors-to-couchdb"

runs every time install runs to build some software. I could have just put the
inside that, which is what I will probably do.

Answer Source

The simplest solution would be to not overwrite the file:

"postinstall": "bash postinstall.sh && cp -n .env.sample .env",

(note that I propose to use cp instead of mv so that you don't remove the default file)

Another (frequent) one would be to simply ask the user to do it. It's a light task compared to all the configuration he has to do anyway.