1

First, I would like to check for latest changes in config files in Git repo without pulling them.

Then I would like to pull files individually. The reason is, I have dev/QA/Prod files. I don't want to synch all configs in DEV.

That could lead to Repository design: is it better to have the dev configs in a branch and qa in different branch and so forth. Or is it better to separate in different folders. Or may be different repos (which is more secure for prod data).

Currently I have a repo with folders: DEV/ QA/ Prod

I would like to synch DEV folder when I clone in DEV .. and so on.

Samir
  • 31
  • 2
  • [Checking for changes on a remote](https://stackoverflow.com/questions/2514270/how-to-check-for-changes-on-remote-origin-git-repository). [Pulling individual files](https://stackoverflow.com/questions/16230838/is-it-possible-to-pull-just-one-file-in-git). And the question about repo design for environments will lead to opinions, not factual answers, but from my experience that will lead to a mess and you're better off using subdirectories for that purpose. Separate repos would be even messier. – Zac Anger Nov 30 '22 at 03:54
  • @ZacAnger - I would be wary of considering Q&A from 2010-2013 as relevant, even for a very slow-paced project like Git – Lazy Badger Nov 30 '22 at 04:29
  • Just **don't do it** in such *shitty way*. Clone|sync repo, have "branch per environment" and don't reinvent the wheel. Period – Lazy Badger Nov 30 '22 at 04:32
  • Please have a read of https://12factor.net/config and consider _not_ storing config in your repo at all - which is the root of the problem. – AD7six Nov 30 '22 at 07:50

1 Answers1

1

The reason is, I have dev/QA/Prod files. I don't want to synch all configs in DEV.

That is why your actual config files should remain private (not tracked by Git).
You should only track config file values, plus a config file template

 prod.conf
 dev.conf
 conf.tpl

Then, you can use a content filter driver, using .gitattributes declaration.

smudge (image from "Customizing Git - Git Attributes", from "Pro Git book")

The script generate conf file by replacing placeholder values with the values of the <branch.conf> file, each time you checkout a branch.
You can know about the current branch name with:

branch=$(git rev-parse --symbolic --abbrev-ref HEAD)

The generated actual conf remains ignored (by the .gitignore).
No synchronization issue during merges.

The smudge script selects the correct value file and generates the correct conf based on the template the smudge script is applied on during a git switch (or old git checkout).

See a content driver setup example at "git smudge/clean filter between branches".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This is a great answer - but I wonder how often it’s the “right” answer instead of changing the source code to read config by `DB_DSN = os.environ.get('DB_DSN')` or similar and _not_ embedding env-specific data in the code repo at all. Personally I don’t think this is a problem git should be used to solve, e.g. I’ve never used it on projects from personal projects to massive systems at scale. – AD7six Nov 30 '22 at 08:04
  • @AD7six I agree, this would not be a good fit for all config values, and an external source/vault is preferable. – VonC Nov 30 '22 at 09:13