By Dmitri Farkov

2013-12-29 04:11:01 8 Comments

Searching for the best approach to keep my config files separate, yet not introduce extra steps for new developers setting up their environments.

I am guessing a submodule would suffice to do the job, but then how would I switch configs seamlessly depending on the task at hand, aka pull in DEV config regularly, pull PROD branch of config repo during build?

Needs to be:

  • Easy and painless for new devs.
  • PROD config files should only be accessible to select users + build user.

Thank you in advance.


@VonC 2013-12-29 07:05:32

That is called content filter driver, and it allows you to declare, in a .gitattributes file (and only for your config files type) a smudge script which will automatically on checkout:

  • combine a config file template file (config.tpl)
  • with the right config file value (,, ...)
  • in order to produced a non-versioned config file (private file)

enter image description here

See "Customizing Git - Git Attributes":

echo '*.cfg.tpl config' >> .gitattributes
git config --global filter.config.smudge yourScript

With that approach, you don't need submodules, but you can generate as many config file you need depending on your environment, like for instance your branch:
A bit like in "Find Git branch name in post-update hook", your smudge script can find out in which branch it is currently executing with:

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

@Dmitri Farkov 2014-01-14 16:49:00

Thank you. Although I ended up going the route of storing configs separately and puppetizing my setup, this is still great info and I never knew about this feature before.

Related Questions

Sponsored Content

11 Answered Questions

25 Answered Questions

[SOLVED] Detach (move) subdirectory into separate Git repository

22 Answered Questions

[SOLVED] Git keeps prompting me for a password

  • 2011-10-14 20:24:17
  • Catherine
  • 325931 View
  • 622 Score
  • 22 Answer
  • Tags:   git github

16 Answered Questions

[SOLVED] Where does git config --global get written to?

  • 2010-01-22 00:34:55
  • Ian Vaughan
  • 676220 View
  • 964 Score
  • 16 Answer
  • Tags:   git config

9 Answered Questions

[SOLVED] Can I delete a git commit but keep the changes

  • 2013-04-02 18:56:15
  • tanookiben
  • 355112 View
  • 932 Score
  • 9 Answer
  • Tags:   git undo git-reset

18 Answered Questions

[SOLVED] git: Your branch is ahead by X commits

  • 2010-03-12 12:15:54
  • SeanJA
  • 313867 View
  • 356 Score
  • 18 Answer
  • Tags:   git git-commit

12 Answered Questions

[SOLVED] What's the best practice to "git clone" into an existing folder?

  • 2011-03-21 13:04:52
  • ripper234
  • 301742 View
  • 422 Score
  • 12 Answer
  • Tags:   git

5 Answered Questions

[SOLVED] How to create a new empty branch for a new project

37 Answered Questions

[SOLVED] Git for beginners: The definitive practical guide

  • 2008-11-24 23:50:29
  • Adam Davis
  • 693739 View
  • 854 Score
  • 37 Answer
  • Tags:   git version-control

Sponsored Content