Git attributes is not a concept that we learn in the early days when familiarizing with Git. Not every experienced software engineer is familiar with it due to its uncommon usage. However, when working on larger or open-source projects with multiple collaborators, using Git attributes can be vastly more efficient than ignoring them. This article introduces Git attributes and presents some of the use cases.
Introduction to Git attributes
Git attributes customize Git to behave differently for each repository. They apply path-specific settings to subdirectories or subsets of files. These settings can configure things such as end-of-line normalization for text files or diff algorithms for binary files.
Git attributes are set either in the .gitattributes
file of one of your directories (usually the root of the project) or the .git/info/attributes
file. The later is used when you don’t want the attributes to be committed in your project tree.
Each line in these files is of the form:
pattern attr1 attr2 ...
pattern
matches paths using the same rules as in .gitignore
files, with a few exceptions:
- negative patterns are forbidden
- patterns that match a directory do not recursively match paths inside that directory (so…