gitline-endingscore.autocrlf

git: always force windows line endings for repo


I want to force my repo to always use windows line endings, regardless of the user's environment or the setting of core.autocrlf. I've read about using .gitattributes to set the line endings, but haven't been able to make that work. My .gitattributes file looks like this:

* text=auto
* text eol=crlf

After adding this file, I run git add --renormalize . and git add .gitattributes, then push to remote. However, this is not overriding my global core.autocrlf setting. What I want is to push my windows line endings to Bitbucket, but what I'm getting is linux line endings in Bitbucket.

How can I force my git client to push Windows line endings for a specific repo, regardless of the user's setting for core.autocrlf?


Solution

  • First, you have two conflicting settings. * text=auto and * text eol=crlf are not compatible. You need to pick one.

    However, I regret that neither will do what you want. Git has no option that is "always convert to CR/LF in the repository". Your only options control what goes into the working directory.

    For example, * text eol=crlf will put Windows-style line endings in the working directory but will put Unix-style line in the repository.

    You can disable line ending configuration entirely by using * -text, but this will simply stop doing text conversion and check in the file literally as it exists on disk. It does not eliminate the possibility of a Unix user rewriting the file with Unix-style line endings.

    I would encourage you to ignore the contents of the file that exists in the repository, and focus on what you want in working directories instead. If you always want CR/LF on disk then use * text eol=crlf.