Zaar Hai Zaar Hai - 1 year ago 61
Git Question

Storing git config as part of the repository

I'm using filters to mangle files during checkout like described here.
Now the problem is that filter definition is only stored in my local configuration file:

$ cat .git/config
[filter "dater"]
smudge = /home/.../expand_date
clean = perl -pe \"s/\\\\\\$Date[^\\\\\\$]*\\\\\\$/\\\\\\$Date\\\\\\$/\"

If my coworkers want to benefit from this
expansion, they need to copy my filter definition. And if I change it, I need to notify them, etc..

So can I store this filter definition part of
in repository and make git use it?

Answer Source

There are 3 supported scopes of .gitconfig file: --system, --global, --local. You can also create a custom configuration file, and include it in one of the supported files.

For your needs custom - is the right choice. Instead of writing your filter in .git/config you should save it in .gitconfig file in your repository root:

├── .git/
│   ├── config
├── .gitconfig

Create the .gitconfig with your filter and commit the changes. Then your colleagues will always keep it updated -- but they will have to include it manually. It is not possible to automatically include your custom configuration file through git alone, because it creates a security vulnerability.

To apply this configuration for a single repository, each user will need to run the following command in your-repo/:

git config --local include.path ../.gitconfig

Be careful not to store personal data in the custom .gitconfig, like user.*, keep those in your global .gitconfig.