5

I begin to use git for software development.

I have a project on github. This project also involves some user-settings stored in dedicated settings-files.

On github the settings should be empty (like this)

### Settings:

## Your name
$name = "";
## Your email adress
$email = "";
## and so on

However, I also have the project running on my computer (or server). My personal version of the project should have all settings filled out.

I would like to have two branches for that. The personal branch should contain all my settings. The master branch should be the one where I develop the software and which I upload to github.

I would like to merge the master branch into the personal branch from time to time to keep my system up-to-date. However, whenever I try to merge the branches, my personal settings get lost.

Is there a way to do this or am I just doing something wrong (what)?

speendo
  • 13,045
  • 22
  • 71
  • 107
  • Could it be that you are (ab)using your build directory also as the producting/test directory? Those should be different things. – pmr May 13 '12 at 02:19
  • why should they be different? in the end, that means I would have to do all changes again after finishing testing. Thought one of the many advantages of git is that this is not necessary. – speendo May 13 '12 at 02:23
  • 1
    It is common to split testing from production, even the build-type would have to differ and the installed program should end up in some standard location and read the configuration from some standard configuration. – pmr May 13 '12 at 12:15

3 Answers3

3

In your personal branch, you could keep:

  • the GitHub config file unchanged (with no value), but with a different name (config.template for example)
  • a "value file" with your personal value
  • a "smudge" script able to generate the actual config file using the template one and your personal values

That script is triggered on any git checkout as a content filter driver.

enter image description here

That way, you can merge master onto your personal branch as many time as you want, your config values will not be modified.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Pretty kludgy to have to do it like this. It would be better if git simply had a way to force merge conflicts on some kinds of files, which would trigger the 'ours' merge driver. Somewhat related: Raymond Chen's ["The merge conflict that never happened (but should have)"](https://devblogs.microsoft.com/oldnewthing/20180313-00/?p=98225) I suppose one can fake that by having a filter that always appends something to your file, which would force the merge driver to activate. – Fizz Jan 21 '22 at 14:05
  • @Fizz 9 years after having written this answer, I agree. This is not exactly straightforward. – VonC Jan 21 '22 at 14:39
2

You can create a setting file like setting-sample, and modify .gitignore to ignore the real setting file (i.e. setting). So the empty setting file will be kept in remote repo, and your personal setting file will be kept in your local repo.

Kjuly
  • 34,476
  • 22
  • 104
  • 118
1

You may commit the empty settings file and then commit a .gitignore file pointing to the original file, so in that case, the users would download the file but git will ignore the changes that users make.