Where should I place my global gitattributes file?

I see that there is (despite the lack of documentation) a way to set Git attributes globally; but I don’t know where to put the necessary gitattributes file. Instructions say they belong

 $(prefix)/etc/gitattributes 

But where is $(prefix) ? In particular, where would it be for OS X (with Git in /usr/local/git/bin/git )? Alternatively (or additionally) will ~/.gitattributes work ?

+40
git unix path gitattributes
Jan 19 '15 at 14:21
source share
1 answer

Global and system-wide settings

There is some ambiguity in your question. In the context of Git, "global" usually means "user level"; in other words, global settings affect all repositories for one specific user (active). In contrast, a system-wide parameter affects all repositories for all users of the machine.

Gitattributes repository level

(I mention this for completeness only.)

According to the relevant section of the Pro Git book ,

If you want to work on only one repository (i.e. $GIT_DIR/info/attributes files, $GIT_DIR/info/attributes to the $GIT_DIR/info/attributes process for one user for this repository), then the attributes should be placed in $GIT_DIR/info/attributes .

$GIT_DIR usually expands to <path-to-repo-root-directory>/.git .

Global (user level) gitattributes

According to the relevant section of the Pro Git book ,

Attributes that should affect all repositories for a single user should be placed in the file specified by core.attributesfile configuration core.attributesfile [...]. Its default value is $XDG_CONFIG_HOME/git/attributes . If $XDG_CONFIG_HOME either not set or empty, $HOME/.config/git/attributes is used instead.

You can also run the following command,

 git config --global core.attributesfile <path> 

point Git to the user path <path> for your global gitattributes file, e.g. ~/.gitattributes .

System-wide gitattributes

According to the relevant section of the Pro Git book ,

Attributes for all users in the system must be placed in the $(prefix)/etc/gitattributes .

which naturally raises the question:

[...] But where is $(prefix) ?

See what $ (prefix) is for $ (prefix) / etc / gitconfig? for answer. If you did not assign prefix custom nonempty value, $(prefix) expands to zero by default; therefore, your system-wide gitattributes file must be in /etc/ .

+62
Jan 19 '15 at 15:07
source share



All Articles