100

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
  • 42,413
  • 44
  • 197
  • 320

2 Answers2

135

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"
  • 7
    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
  • 6
    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
  • 2
    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
  • 5
    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
  • 4
    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
  • Why do we need two git config functions? – einpoklum Oct 07 '21 at 07:58
  • I don't know, but it's needed the Filter Process (https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-filter-process.1.ronn) and the Smudge (https://github.com/git-lfs/git-lfs/blob/main/docs/man/git-lfs-smudge.1.ronn). – Marcelo Ávila de Oliveira Oct 07 '21 at 18:42
  • @ideasman42: Could you elaborate what exactly what was left in your .gitconfig? I just tried it out on Linux: Without git-lfs, the file was just not fetched, instead I had a small file with the hash etc. After installing git-lfs, it was fetched automatically. But I don't see any change in my ~/.gitconfig ... But actually, I do see a section [filter "lfs"] in my /etc/gitconfig, so maybe that solves the mystery. – Jens Müller Dec 10 '21 at 21:57
  • this does not work at all! it maybe works on some peoples projects, but not on mine, maybe some little difference somewhere, looking forward to the next 3 hours of googling and trial n' error. this is classical git behavior all over again, I don't understand why they didn't just make this straight forward or usable, I guess usability is the mortal enemy in this scenario... this is quite literally the very first anybody using LFS is trying to figure out and it's like finding nemo – DanDan Feb 27 '23 at 09:19
33

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
  • 431
  • 5
  • 4