git-lfs icon indicating copy to clipboard operation
git-lfs copied to clipboard

Don't automatically download LFS objects (for all users)

Open jextrevor opened this issue 9 years ago • 11 comments

I've set up Git LFS in a repo I am working on. The repo contains several large files, and several hundred more large files will be added in the future. It is annoying when these files are automatically downloaded as part of git pull.

Is there a config option that I can put in .lfsconfig in our repo that will disable the automatic downloading of LFS files for all users of the repo? Automatic upload is fine, I just want to disable automatic download.

jextrevor avatar Nov 04 '17 21:11 jextrevor

You can set lfs.fetchexclude to *:

https://github.com/git-lfs/git-lfs/blob/ac19b5e1ff3853aab07f15ac8f8f6c8f50aacb83/docs/man/git-lfs-config.5.ronn#L163-L173

Keep in mind, this can be overridden by a local git config change or command line flag. The order of preference for this change is:

  • .lfsconfig
  • User Global Git config
  • User local Git config
  • Command line flag

Here's the command line flags that git lfs pull can accept in case they do need some files:

https://github.com/git-lfs/git-lfs/blob/ac19b5e1ff3853aab07f15ac8f8f6c8f50aacb83/docs/man/git-lfs-pull.1.ronn#L18-L35

Checking this change in .lfsconfig will ensure that users will not download LFS files by default.

technoweenie avatar Nov 06 '17 15:11 technoweenie

@technoweenie

What does this look like in ~/.gitconfig

I currently have the following, and it doesn't seem to work:

[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true
	fetchexclude = *

thomasbiddle avatar Jun 14 '18 17:06 thomasbiddle

@thomasbiddle it should look like the following:

[lfs]
	fetchexclude = *

(note that [lfs] != [filter "lfs"]).

ttaylorr avatar Jun 14 '18 17:06 ttaylorr

@ttaylorr That worked - thanks!

thomasbiddle avatar Jun 14 '18 22:06 thomasbiddle

If using the mentioned setting in .gitconfig you then need to use git lfs pull --exclude= --include "filename" to pull a single file. Took me a while to figure that one out.

ranebrown avatar May 10 '19 21:05 ranebrown

Once I've excluded the files, how do I purposely download them in a specific scenario?

camilla11 avatar Jun 14 '19 15:06 camilla11

You can use git lfs fetch --include="filename" --exclude="" to override the default include and exclude settings and download the given file. You can also replace filename with a glob pattern and it will include all files matching that pattern.

bk2204 avatar Jun 14 '19 16:06 bk2204

hmm that didn't work but

git lfs pull --include="*" --exclude="" did ! Thank you

camilla11 avatar Jun 14 '19 16:06 camilla11

How do I go about adding this to .gitattributes?

When I the recommended above to .gitattributes and then try a fresh clone I'm getting the following output:

 is not a valid attribute name: .gitattributes:30

with line 30 of my .gitattributes looking as follow:

...
26 *.xlsx filter=lfs diff=lfs merge=lfs -text
27 *.XLSX filter=lfs diff=lfs merge=lfs -text
28 original/*  filter=lfs diff=lfs merge=lfs -text
29 [lfs]
30 	fetchexclude = *

Any idea why that's happening?

Screen Shot 2021-02-01 at 2 12 41 PM

horak avatar Feb 01 '21 20:02 horak

Those values don't go in .gitattributes. They should live in your local Git configuration file, such as in .git/config.

bk2204 avatar Feb 01 '21 22:02 bk2204

Doh. Thanks!

horak avatar Feb 02 '21 01:02 horak