2

I've got a master branch, which contains some config file templates, I want to make it so that when I branch off the master branch, it creates these templates in the sub branch, however, any further changes on the master branch to these config templates won't be pulled down into the sub branch, so sub-branch configs aren't overridden.

Now the tricky bit is that, I still want the sub-branch config files to be tracked, so I'm still able to make changes in the sub branch config files and push it back up to the sub branch.

How do you think I could go about accomplishing this?

uneatenbreakfast
  • 545
  • 6
  • 15
  • Do you want the changes that you are doing for the master to be reflected in the sub branch? question is unclear – DilumN Jan 30 '17 at 03:31

1 Answers1

1

I branch off the master branch, it creates these templates in the sub branch

That seems easy: when you branch off master, any file present in master would be in the new branch.
But:

any further changes on the master branch to these config templates won't be pulled down into the sub branch

Any further change would still be in any new branch.

So:

  • version those original template file in a "template" branch (where you agree those files won't change anymore: no new commit, you can protect the branch if you are working with GitHub or BitBucket or GitLab)
  • Put in place a content filter driver which will automatically on checkout (of any branch)

    • check if those files are in the checked-out branch (if not they would be copied from the template branch). It will also add a .gitattributes file with a merge=ours directive to ensure those files are not overridden in case of merges.
    • won't do anything if those files are already there (meaning any changes are

However, the all setup is quite complex.

A simpler solution would be to have different template files, and a script able to use the right one depending on the branch currently checked out.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    +1 for the separate files. Since the branch is separate, doing that will simplify the process very much and at some time, if you don't want the separate files any more, you can simply delete them. – Noufal Ibrahim Jan 30 '17 at 05:44
  • @NoufalIbrahim I agree, after explaining such a complex possible solution, I wanted to propose an alternative ;) – VonC Jan 30 '17 at 05:46