8
- When should I use the
.gitattributes
? - What can I do with it ?
- When not using this file ?
- It’s good practice to always have a file
.gitattributes
in my repositories ?
8
.gitattributes
?.gitattributes
in my repositories ?5
The . gitattributes file serves as a control for a number of GIT actions. I do not know any contraindications to its use, however, as always, it is important to make its use consciously, avoiding unexpected results. There are a number of well-documented templates and many Ides also create the same by initializing a new repository.
The most common use of . gitattributes may be for controlling line endings. Taking the default Visual Studio as an example:
* text=auto
*.sh text eol=lf
* text=auto
will cause GIT to use its default for text files and convert files CRLF for LF at checkin, for example. This way the repository will be left with a single pattern, even if different operating systems are used.
*.sh text eol=lf
will cause the files .sh
are excluded from the above behaviour, remaining as LF
. This is especially useful when you have files .sh
on a Windows computer used in Linux containers.
Similarly, we can have the same for typical Windows files like .bat
, .cmd
and .ps1
.
An interesting use is for the export-ignore
, allowing "delete" directories and files when exporting a repository (such as when users download the repository as .zip directly from Github). In this case, specific GIT files (such as .gitignore and .gitattributes itself) as well as test directories and other artifacts that should not be relevant to people who just want to run something from their repository could be deleted.
4
The . gitattributes is a simple text file that provides specific attributes for files and directories within your repository. With it you can configure several things, such as: solving visual diff problems in your merge request, selecting an automatic action when there are conflicts, converting end of lines into text-based files, etc...
You can read more on this subject here
Browser other questions tagged git
You are not signed in. Login or sign up in order to post.