1

Because I use core.autocrlf on Windows, my linefeeds that I commit and push to GitHub get normalised from CRLF -> LF which is good. When I clone on Windows they get converted back LF -> CRLF. However I want to download my repo as zip on a Windows machine without git installed. Now the linefeeds are incorrect for Windows.

Is there a way to download files from GitHub without git installed but still adding the CRLF back to the files?

Greedo
  • 4,967
  • 2
  • 30
  • 78
  • 1
    I don't have a solution, but that's the major problem with `core.autocrlf`: it's *local configuration* and not part of the repository itself. That's why I (and many others) have switched over to configuring line endings via `.gitattributes` exclusively: that file (just like `.gitignore`) is actually part of the repo and its settings are applied everywhere (I *suspect* they also apply to the ZIP export, but haven't tried). https://stackoverflow.com/a/10855862/40342 – Joachim Sauer Jan 11 '23 at 09:36

2 Answers2

1

After some testing, it seems that if you use a eol=crlf property in your .gitattributes file, GitHub will perform the line-ending conversion for the files matching the pattern.

eg.:

*.bas text eol=crlf

This will work when you download the repository as a zip file

enter image description here

However, it won't work if you download a raw file (the lines will remain as LF):

enter image description here


On a related note, assuming you are working with an old-school Windows specific codebase like a VB6 or VBA project, you might also want to define the text encoding in case you have non-ASCII characters like "€", "©", "£", etc.

eg.:

*.bas text eol=crlf working-tree-encoding=CP1252

In my case, I'm using CP1252 which is the usual Windows code page for Windows OS in North American and Western Europe, but it might differ on your system. To get the number that goes after "cp" on your local machine, you can run the following Powershell command :

Get-WinSystemLocale | Select-Object @{ n='ANSI Code Page';   e={ $_.TextInfo.AnsiCodePage } }

source

DecimalTurn
  • 3,243
  • 3
  • 16
  • 36
0

When you download an archive from GitHub, it's essentially generated with git archive. That means what you get in the archive is what's in the repository, which means that Git doesn't perform CRLF translation. GitHub doesn't provide an option to adjust this because Git doesn't provide such an option.

What you're doing using LF in the repository and CRLF in the working tree (if you want that) is the right way to work with Git, and you should keep doing that.

If you want to do a release with a zip file that contains files with line endings different than what's in the repo or with additional files that aren't included in the repo, then create a release on GitHub and upload such an archive as a release asset. Then you can include whatever line endings you want or whatever else you want in the archive and have it available without the repository. Many common projects do exactly this.

bk2204
  • 64,793
  • 6
  • 84
  • 100