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.

1 comments

@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 (config.dev, config.prod, ...)
  • 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:

#!/bin/sh
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

[SOLVED] How do I show my global Git configuration?

  • 2012-09-03 21:14:17
  • wullxz
  • 649694 View
  • 886 Score
  • 11 Answer
  • Tags:   git

17 Answered Questions

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

  • 2010-01-22 00:34:55
  • Ian Vaughan
  • 651514 View
  • 924 Score
  • 17 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
  • 310905 View
  • 832 Score
  • 9 Answer
  • Tags:   git undo git-reset

21 Answered Questions

[SOLVED] Git keeps prompting me for a password

  • 2011-10-14 20:24:17
  • Catherine
  • 307270 View
  • 585 Score
  • 21 Answer
  • Tags:   git github

18 Answered Questions

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

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

8 Answered Questions

24 Answered Questions

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

7 Answered Questions

[SOLVED] What are some examples of commonly used practices for naming git branches?

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
  • 687303 View
  • 854 Score
  • 37 Answer
  • Tags:   git version-control

Sponsored Content