I am using GitLab in my project and I have a quite specific workflow. I have 2 branches "Dev" and "Release" as shown below. When I submit a merge request from Dev to Release, the config files are also getting overwritten with that of Dev branch.
But ideally config files have to be different for both of these branches. I tried to use merge=ours
. But it didn't serve my purpose as it will not override until and unless there is a conflict in config files. I don't want to add these files in .gitignore
, as any changes to these files will not be committed in Dev branch. Can someone please guide me how to achieve this?
You can simply make sure your config files for dev and master are named differently, with their own history. That way, a merge will never overwrite anything.
You can then version and track:
config.tpl
(template file with placeholder values).config
file (which remains untracked, private).gitignore
which ignores the resulting generatedconfig
file.gitattribute
declaring a smudge content filter (see below)The generation of the config file is automated through a content filter driver, using a
.gitattributes
declaration.(image from "Customizing Git - Git Attributes" from "Pro Git book"))
Once you declare that content filer driver in your local config, it will automatically, on
git checkout
, generate yourconfig
file for you.See a complete example in "Best practice - Git + Build automation - Keeping configs separate".