I frequently find myself changing a single variable in my project within Git to connect to a different server while on the Development branch (in JavaScript, so I can\'t use
No, there isn't, but this is a well-solved problem.
You have a few options:
config.example
file which lists all the configuration options that need to be specified, and provides sane defaults for development.config.example
to the real config filename, and add real values.gitignore
.setup.sh
script, which copies config.example
to the real config's location, and populates it with variables for the local environmentAs an example, you might have a JavaScript application which needs to know where its database is, and reads this information from config/database.json
. You might use something like this:
// config/database.example.json
DATABASE = {
"host": "localhost",
"user": "#TODO",
"pass": "#TODO",
}
To get running in development, you would copy this file to config/database.json
, and fill in the values appropriate to your dev environment.
In production, you'd have a config/database.json
that contained production values, but was not version controlled.
The repo would have config/database.json
in its .gitignore
.
config.development
and config.production
etcIf there is anything remotely sensitive in your config file, such as AWS keys or any form of password, you should use the first option - store the configuration option's name, but not its value, and require users to supply their own credentials, obtained through secure channels outside of version control.