Search code examples
gitbitbucketexcept

Different branch with one unique file in git


I have a project with a git server . We are two dev working on it and each of us have to use a different token for some api. I also have one other api key for my master branch, dev branch and testing branch. All the api tokens are stocked in a config.json file, which means 5 differents config.json.

The problem is : I want to have my config.json unchanged when push or merge one branch commit to another.

I have try some solution with the .gitignore file and git update-index --assume-unchanged config.json but none of them seems to be adapted to my case. I have also found the .git/info/except file, who really seems to be what I need but whatever I try, the config.json appear "modified".

So if you have a possible solution, other than that, or the reason why my exept do not work, it would be really helpful!

Regards, Eiji


"Lack of better" Solution :

I have use the solution of @gus3001. I have made a folder configs with all the differents configs (dev / master / testing / etc) in it, and another, preset.json, which is referenced in .gitignore.

So on each branch switch, we just have to modify a short string in the ignored file. It still can be confusing and risky, so if you have a better solution, please share it.


Solution

  • How I would normally solve this problem is to place user-dependent configuration in a separate file. So in you case, I would take the api-token out of the config.json and put it in an git-ignored file, something called user-config.json perhaps.

    This will likely mean that you have to change your code to get the token from the new user-config.json, but the benefit is that you can actually track the non-user-dependent config in config.json normally, without worrying about making it ignored by git only when the token is different but not when something else has changed.

    tl;dr

    User dependent config should be in a separate git-ignored file to avoid such issues.