Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jextrevor opened this issue Nov 4, 2017 · 11 comments
Closed

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

jextrevor opened this issue Nov 4, 2017 · 11 comments

Comments

@jextrevor
Copy link

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.

@technoweenie
Copy link
Contributor

technoweenie commented Nov 6, 2017

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.

@thomasbiddle
Copy link

@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 = *

@ttaylorr
Copy link
Contributor

@thomasbiddle it should look like the following:

[lfs]
	fetchexclude = *

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

@thomasbiddle
Copy link

@ttaylorr That worked - thanks!

@ranebrown
Copy link

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.

@camilla11
Copy link

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

@bk2204
Copy link
Member

bk2204 commented Jun 14, 2019

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.

@camilla11
Copy link

hmm that didn't work but

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

billsacks added a commit to billsacks/ctsm that referenced this issue Mar 27, 2020
Based on git-lfs/git-lfs#2717

The purpose of this is two-fold:

(1) It keeps clones and fetches lighter-weight

(2) It keeps our LFS bandwidth down, so we're less likely to need to
upgrade our account (though that may be free for our educational
account).
JeffersonMontgomery-Intel added a commit to GameTechDev/PresentMon that referenced this issue Apr 3, 2020
Currently setup to not download files by default.  For users that need
the large files, this can be overridden by local git config or command
line, e.g.:

git lfs pull --include="*" --exclude=""

See git-lfs/git-lfs#2717
billsacks added a commit to billsacks/ctsm that referenced this issue Apr 7, 2020
Based on git-lfs/git-lfs#2717

The purpose of this is two-fold:

(1) It keeps clones and fetches lighter-weight

(2) It keeps our LFS bandwidth down, so we're less likely to need to
upgrade our account (though that may be free for our educational
account).
@horak
Copy link

horak commented Feb 1, 2021

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

@bk2204
Copy link
Member

bk2204 commented Feb 1, 2021

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

@horak
Copy link

horak commented Feb 2, 2021

Doh. Thanks!

fritzt pushed a commit to CESM-GC/CTSM that referenced this issue May 19, 2021
Based on git-lfs/git-lfs#2717

The purpose of this is two-fold:

(1) It keeps clones and fetches lighter-weight

(2) It keeps our LFS bandwidth down, so we're less likely to need to
upgrade our account (though that may be free for our educational
account).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants