How to manage configuration files while working together?

I am writing a short script with a few simple variables at the top of the page. I want to work with them with a friend, but we donโ€™t know how to manage the variables that need to be changed, each time pulling one of us, adding an unnecessary unwanted element to the git state. I was thinking about creating different name branches for each of us, and then the wizard will have only an example of using usernames, but it seems silly to do everything that does the extra work of merging. We could pass variables into script parameters like this, but this is undesirable, and not split it into another separate configuration file. It would be great to have something like .gitignore, but just ignore a few lines in the file.

How can it be elegantly managed? How is this problem usually managed?

+45
git gitignore configuration-files
Jan 20 2018-11-11T00:
source share
5 answers

You cannot just simply ignore changes in certain lines of the file, I'm afraid, so you are probably stuck with a separate configuration file. Below I have listed two typical ways to deal with this, and one a bit more exotic:

Have an example config file in git

Here you would save the config.sample file in git as an example, but the application would actually use the values โ€‹โ€‹in the config file, which is located in .gitignore . Then the application will throw an error if config not present. You must remember to change the values โ€‹โ€‹in the sample file when adding new configuration variables to your personal config file. In this case, itโ€™s also good that your application checks that all the necessary configuration parameters are actually set, in case someone forgot to update their config file after making changes to the sample.

Has a default values โ€‹โ€‹file in git

You save the config.defaults file in git, which, as far as possible, has reasonable default configuration values. Your first configuration of your applications is from config.defaults and then from config (which is located in .gitignore ) to possibly override any default values. With this method, as a rule, you would not make a mistake for the config not exist, so the application can work out of the box for people who did not bother to create a config .

Using a single configuration file with the -assume-immutable option

The third possibility, which I would not recommend personally in this case, would be to have one configuration file that was fixed in git, but use git update-index --assume-unchanged <FILE> to tell git to ignore the changes to him. (This is described later in this useful blog post .) This means that your local changes to the configuration file will not be submitted using git commit -a or displayed in git status .

+51
Jan 20
source share

In my case, I have the "config" variables in a separate (small) file, like all other developers on the team. Things like my database location, etc. are stored there. We put the name of this file in our .gitignore so that it is not version controlled, but checks the file "sample_config" so that beginners can make a copy and use it for their own purposes.

+4
Jan 20 '11 at 6:20
source share

A Python / Django-specific solution is to have common settings.py files that have been checked in the repository, and a local settings_local.py , imported at the end of settings.py , which overrides some parameters using specific value machines.

+3
Jan 20 2018-11-11T00:
source share

Other options (not elegant, but may be useful):

  • Use git stash and git stash pop for your config file
  • Have a branch named, say config, that has a local configuration file, and then use git checkout config <your config file>

The second option is good if you need to save local configuration changes in a repo (somewhere).

+3
Jun 30 '11 at 17:47
source share

You can create an additional repository for local settings and symbolize the files / folder in your project.

See my answer in another thread for more details.

0
Dec 08 2018-11-12T00:
source share



All Articles