Ken Muse

Creating a .gitattributes Without Committing


Continuing our discussion of Git configurations, sometimes we need the ability to utilize the features provided by .gitattributes without having to add or modify a .gitattributes in the current repo. This is very similar to how we handled .gitignore. We have very similar options.

First, we can work with just the local repository. To specify local settings without committing a .gitattributes, you need to create a repository file: .git/info/attributes. This file provides the same features as .gitattributes, but it will not be committed or shared with other users. This creates a configuration that only affects the local repository.

Alternatively, we can create a global attributes file. Git resolves this file by looking at the configuration value core.attributesFile. This path defaults to $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is not set, then the default is %HOME/.config/git/attributes. The Git configuration can be manually specified with:

1git config --global core.attributesFile {path}

Finally, there is an additional option available if you want to create a configuration that affects all users. To do this, the file should be placed in /etc/gitattributes.