repository - How to prevent tracked config files from being changed by merges in git? -


i have web project 2 git branches (developing , production) , each 1 connects different server (dev , prod). each branch has set of tracked config files, such different urls, database options, sql exported files, etc. different on both branches.

every time try merge branches lot of conflicts in these settings files need resolved manually, every , miss something. in short, nightmare. question therefore, how can avoid this?

  • is there way prevent changes config files while merging or rebasing?*

suggested solution: "try make files untracked". tried whenever pulled production file files deleted , replaced, don't know if should in different way.

the way register merge strategy per-file attribute use current version. here how (the idea this blog)

first register merge driver that

  • does nothing and
  • exits successfully.

the shell command true looking for. following line registers true alwaysours merge driver:

git config --local merge.alwaysours.driver true 

next, need tell git files use bogus merge driver. .gitattributes file for. supports same small set of file patterns .gitignore file. example

/configs/* merge=alwaysours *.conf merge=alwaysours 

would use our bogus merge driver files in '/config' or files ending '.conf'. makes sense add file git repository

git add .gitattributes 

so changes tracked. there 1 caveat though: when merge in branch having .gitattributes file, alwaysours driver used on branch! avoid problems arising that, add alwaysours merge driver .gitattributes on all branches.

echo '/.gitattributes merge=alwaysours' > .gitattributes git commit .gitattributes -m 'register alwaysours driver .gitattributes' 

of course break proper handling of other settings have in .gitattributes.


Comments