6

I want to clone a GitHub repo that has a giant .exe file in it. (why?!) I have zero use for the .exe file, and it is substantially bigger than everything else combined. Is there a way to ignore the file when I clone it?

My guess is that I would have better luck asking the author to make an exe-less branch! Hopefully there is some nice way around this though.

mrKelley
  • 3,365
  • 2
  • 21
  • 28
  • Related: http://stackoverflow.com/questions/14326365/git-clone-ignoring-a-directory – Lajos Veres Apr 17 '14 at 22:01
  • I definitely saw that first, and wasn't satisfied. So, I asked a slightly more specific question. One answer states that `git clone` will always clone the whole thing, so I'm asking if there is any way to achieve my goal of not having to download the exe, and yet automate this with a git command. – mrKelley Apr 17 '14 at 22:03
  • I don't think so based on these answers. It looks you have to download it, but you can filter out later. – Lajos Veres Apr 17 '14 at 22:05
  • 1
    Accepted answer below works like a charm – mrKelley Apr 18 '14 at 17:13
  • If you check the comments in the linked answer (or your respository's internals), you will see that the big exe is downloaded, but it is filtered from your working copy. The clone doesn't care about the sparse checkout properties when downloads, this property is important when copying the files from the .git folder to the working copy. – Lajos Veres Apr 18 '14 at 19:00
  • :( How would I verify that in the "repository's internals." Where/how do I look for those .exe files I thought I ignored? I don't see them in the repo, but would they be cached somewhere? – mrKelley Apr 18 '14 at 19:11
  • The `sparse-checkout` repo is smaller than the one I get from a regular `git clone`. – mrKelley Apr 18 '14 at 19:19
  • It can happen that I am wrong. I didn't test it. It think this command should display what is in your repo: `git ls-tree $(git log -1|head -1|cut -d ' ' -f 2)` – Lajos Veres Apr 18 '14 at 22:51

1 Answers1

6

2020+: use the more recent git sparse-checkout command (that I introduced here):

This will actually clone without downloading anything:

git clone --filter=blob:none --no-checkout https://github.com/git/git
cd git

I detail the exclusion here:

# Disablecone mode in .git/config.worktree
git config core.sparseCheckoutCone false

# remove .git\info\sparse-checkout
git sparse-checkout disable

# Add the expected pattern, to include just a subfolder without top files:
git sparse-checkout set !/your.exe

# populate working-tree with only the right files:
git read-tree -mu HEAD

2014: You can try a sparse checkout, which means:

  • initializing an empty repo,
  • add a remote pointing to the GitHub repo: git remote add -f origin <url>,
  • git config core.sparsecheckout true,
  • create a .git/info/sparse-checkout file in which you specify what you want to load.

In your case:

/*
!yourExe

You now can do a:

git pull origin master

That should download everything but your exe.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This downloads *everything*, including the exe. It just doesn't check it out in the end. It still wastes space in your .git. – Atemu Jul 17 '23 at 18:08
  • @Atemu You are correct: this 2014 answer is not satisfactory. I have updated it to use the 2020 more recent command `git sparse-checkout`. Let me know if that is working better. – VonC Jul 18 '23 at 06:12