git-lfs/git-lfs

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

jextrevor opened this issue · 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.

You can set lfs.fetchexclude to *:

* `lfs.fetchinclude`
When fetching, only download objects which match any entry on this
comma-separated list of paths/filenames. Wildcard matching is as per
git-ignore(1). See git-lfs-fetch(1) for examples.
* `lfs.fetchexclude`
When fetching, do not download objects which match any item on this
comma-separated list of paths/filenames. Wildcard matching is as per
git-ignore(1). See git-lfs-fetch(1) for examples.

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:

## OPTIONS
* `-I` <paths> `--include=`<paths>:
Specify lfs.fetchinclude just for this invocation; see [INCLUSION & EXCLUSION]
* `-X` <paths> `--exclude=`<paths>:
Specify lfs.fetchexclude just for this invocation; see [INCLUSION & EXCLUSION]
## INCLUSION & EXCLUSION
You can configure Git LFS to only fetch objects to satisfy references in certain
paths of the repo, and/or to exclude certain paths of the repo, to reduce the
time you spend downloading things you do not use.
In gitconfig, set lfs.fetchinclude and lfs.fetchexclude to comma-separated lists
of paths to include/exclude in the fetch (wildcard matching as per gitignore).
Only paths which are matched by fetchinclude and not matched by fetchexclude
will have objects fetched for them.

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

@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 it should look like the following:

[lfs]
	fetchexclude = *

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

@ttaylorr That worked - thanks!

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.

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

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.

hmm that didn't work but

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

horak commented

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

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

horak commented

Doh. Thanks!