This is a fairly common question, and there isn't a One True Answer.
These are the most common techniques:
- Modify your app such that, before loading its config from e.g.
config.ini, it first looks for e.g.config.mine.ini, and loads it instead if it exists. Track a standardconfig.iniin your repo, but if you need to override the values in it, copy it toconfig.mine.iniand modify. Then configure git to ignoreconfig.mine.ini. - Modify your app such that it first loads e.g.
config.ini, but then attempts to load e.g.config.mine.ini, and if it exists, uses keys fromconfig.mine.inito override those obtained fromconfig.ini. This is similar to the first approach, but means thatconfig.mine.inineeds to specify only options that you don't want to override. Thanks to shrugger for this one. - Have your app look at environmental variables for its config, before using the values from its config file. Then set your your shell to load those environmental variables on login. Only works if your app doesn't need much config, but can be a useful behaviour for simple apps.
- Have your app just look for e.g.
config.ini, but don't track this file. Instead create and track e.g.config.sample.ini. Everyone who clones the repo has to copyconfig.sample.initoconfig.ini, but they can modifyconfig.inias much as they want. - Use some gitattributes clean/smudge magic as suggested by SethRobertson, see the other file in this gist.
- Use a local configuration branch. This seems pretty painful, though.
- Not recommended: If all of the previous suggestions won't work for some reason, look at the "assume unchanged" section in man git-update-index. Anyone who's tried this normally ends up hating it.