GitLab - ignore specific files in target branch
Asked Answered
D

1

1

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.

enter image description here

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?

Deviant answered 11/7, 2017 at 0:47 Comment(0)
E
1

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:

  • a config.tpl (template file with placeholder values).
  • two config file, one for dev, one for master
  • a script able to take a config file and a template file, and produce the config file (which remains untracked, private)
  • a .gitignore which ignores the resulting generated config file
  • a .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.

https://static.mcmap.net/file/mcmap/ZG-AbGLDKwfpKnMAWVMrKmltX1ywKmMva3/tumAc.png
(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 your config file for you.
See a complete example in "Best practice - Git + Build automation - Keeping configs separate".

Evangelical answered 11/7, 2017 at 4:50 Comment(1)
Thanks a ton Vonc.Deviant

© 2022 - 2024 — McMap. All rights reserved.