Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I place my global 'gitattributes' file?

I gather there is (despite the lack of documentation) a way to set Git attributes globally; but I'm not clear where to place the necessary gitattributes file. The instructions say they belong in

$(prefix)/etc/gitattributes 

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

like image 891
orome Avatar asked Jan 19 '15 14:01

orome


People also ask

Where do I put the Gitattributes file?

These path-specific settings are called Git attributes and are set either in a . gitattributes file in one of your directories (normally the root of your project) or in the . git/info/attributes file if you don't want the attributes file committed with your project.

What is the purpose of Gitattributes file?

gitattributes file allows you to specify the files and paths attributes that should be used by git when performing git actions, such as git commit , etc. In other words git automatically saves the file according to the attributes specified, every time a file is created or saved.

What is the Gitattributes file?

A gitattributes file is a simple text file that gives attributes to pathnames. Each line in gitattributes file is of form: pattern attr1 attr2 ... That is, a pattern followed by an attributes list, separated by whitespaces. Leading and trailing whitespaces are ignored.

How do I open a Gitattributes file?

If you cannot open your GITATTRIBUTES file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a GITATTRIBUTES file directly in the browser: Just drag the file onto this browser window and drop it.


1 Answers

Global vs. system-wide settings

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

Repository-level gitattributes

(I'm only mentioning this for completeness.)

According to the relevant section of the Pro Git book,

If you wish to affect only a single repository (i.e., to assign attributes to files that are particular to one user’s workflow for that repository), then attributes should be placed in the $GIT_DIR/info/attributes file.

$GIT_DIR would typically expand 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 a file specified by the core.attributesfile configuration option [...]. Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is 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> 

to point Git to a custom 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 on a system should be placed in the $(prefix)/etc/gitattributes file.

which naturally begs the question:

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

See What is $(prefix) on $(prefix)/etc/gitconfig? for an answer. Unless you've assigned prefix a custom, non-empty value, $(prefix) expands to nothing by default; therefore, your system-wide gitattributes file should reside in /etc/.

like image 197
jub0bs Avatar answered Sep 19 '22 10:09

jub0bs