2022-07-27

Committing configuration files

So, the scenario here is that you have a configuration file that you want to be committed so that you have a complete example to work from. The problem is that the completed file might have passwords in it that you don’t want committed to your git repository.

I found the objectively correct answer today. You commit a file with the example first…

My example config.json file:

{
    "my_api_endpoint": "http://apis.kevinja.com/v1/fakeapi/",
    "api_username": "your_username",
    "api_password": "changeme"
}

Then… you do some git magic:

git update-index --skip-worktree config.json

This tells git that you don’t want it monitoring this file anymore.

Now, you can change the file to your heart’s content:

{
    "my_api_endpoint": "http://apis.kevinja.com/v1/fakeapi/",
    "api_username": "kevinja",
    "api_password": "My$uper$3cr1tPa$$w0rd"
}

…and git doesn’t care anymore.

➜  git status
On branch master
nothing to commit, working tree clean

You can always change your mind later:

git update-index --no-skip-worktree config.json

git geekery


Previous post
2022-07-26
Next post
.jpeg