45

Is there a way to explicitly ignore all git-lfs files on clone and pull?
(besides uninstalling git-lfs which I ended up doing).


In this case git-lfs just contains pre-compiled libs for a platform I don't use... so there is absolutely no use in getting them.

ideasman42
  • 30,245
  • 24
  • 136
  • 249
  • Are they in a particular directory? You could try sparse checkout in that case. – Mayur Nagekar Feb 03 '17 at 09:57
  • I'm not sure, they seem to be scattered about, irrespective, if there were a way to opt-out it would be preferable. – ideasman42 Feb 03 '17 at 10:32
  • https://stackoverflow.com/questions/41716509/fail-to-clone-repository-with-git-lfs/46656484#46656484 has required steps. – avp Mar 05 '18 at 01:54

2 Answers2

62

Two alternatives:

(1) Using the GIT_LFS_SKIP_SMUDGE variable:

GIT_LFS_SKIP_SMUDGE=1 git clone SERVER-REPOSITORY

Obs: for "Windows", use the following two commands:

set GIT_LFS_SKIP_SMUDGE=1  
git clone SERVER-REPOSITORY

(2) Configuring the git-lfs smudge:

git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"
git config --global filter.lfs.process "git-lfs filter-process --skip"
    
git clone SERVER-REPOSITORY

To undo this configuration, execute:

git config --global filter.lfs.smudge "git-lfs smudge -- %f"
git config --global filter.lfs.process "git-lfs filter-process"
  • 3
    It would be good if this were possible without installing `git-lfs` at all. Currently this means if I want to make a source package, it needs to depend on `go`, `ruby` + some extras... adding up to over 220mb of deps, simply so I can tell it to be ignored :S – ideasman42 Oct 10 '17 at 03:22
  • 5
    Actually it is. This is the alternative number 0, if you don't install git-lfs all lfs files will be just ignored. – Marcelo Ávila de Oliveira Oct 10 '17 at 11:07
  • 1
    Not on my test with https://github.com/opentoonz/opentoonz I get the errors: `git-lfs: command not found` `error: external filter 'git-lfs smudge -- %f' failed 127` `warning: Clone succeeded, but checkout failed.` – ideasman42 Oct 10 '17 at 12:43
  • 3
    Update, turns out I had once used git-lfs and it was left in by `.gitconfig`. So this can work, it's just not ideal if others are expected to build the package. – ideasman42 Oct 10 '17 at 12:51
  • This still downloads all the LFS objects, so is okay but not ideal. – piojo Jun 19 '20 at 03:05
  • 3
    On windows, use 2 commands: `set GIT_LFS_SKIP_SMUDGE=1` `git clone SERVER-REPOSITORY` – cowlinator Jun 23 '20 at 01:15
  • The git config method (2) still raises a smudge error, only (1) GIT_LFS_SKIP_SMUDGE worked for me – Ed Randall Jan 28 '21 at 14:23
17

I'm currently struggling myself to find a clean way to download (and remove afterwards) large files with git-lfs.

However, there is a third alternative to the post of @Marcelo Ávila de Oliveira:

git lfs install --skip-smudge

will define globally to skip lfs downloads initially, when cloning repositories.


 

EDIT: I've created a tutorial for basic git-lfs handling. Any feedback and suggestions are very welcome.

You can find it at:

https://sabicalija.github.io/git-lfs-intro/

or pull it via:

git clone https://github.com/sabicalija/git-lfs-intro.git

Alija
  • 271
  • 3
  • 4