23

Short question: Is it possible to configure git such that regular git pull will ignore some files?

Problem description: I have a repository that includes some large data files (stored using git lfs)

While some developers who work on the data files need updated versions of these files, other developers need the files, but not necessarily the most recent version.

They do need updated code versions. And the data files are in the same repository as the code.

I want to set up for way that a regular pull wouldn't update the data files.

  • I know it's possible to do a pull without downloading files from LFS, but this will replace the files with pointer files, and I need the previous version of the files.
max630
  • 8,762
  • 3
  • 30
  • 55
Ophir Yoktan
  • 8,149
  • 7
  • 58
  • 106

3 Answers3

20

I ran into this man page, I didn't tested but hopefully it helps:


INCLUDE AND EXCLUDE

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.

Examples:

  • git config lfs.fetchinclude "textures,images/foo*"

    This will only fetch objects referenced in paths in the textures folder, and files called foo* in the images folder

  • git config lfs.fetchinclude "*.jpg,*.png,*.tga"

    Only fetch JPG/PNG/TGA files, wherever they are in the repository

  • git config lfs.fetchexclude "media/reallybigfiles"

    Don't fetch any LFS objects referenced in the folder media/reallybigfiles, but fetch everything else

  • git config lfs.fetchinclude "media"
    git config lfs.fetchexclude "media/excessive"

    Only fetch LFS objects in the 'media' folder, but exclude those in one of its subfolders.

Vincent Cantin
  • 16,192
  • 2
  • 35
  • 57
  • 3
    Note: if you're cloning a repository afresh, you can use `git lfs clone repo.git --include="includes" --exclude="excludes"` – bejado Mar 25 '17 at 18:40
  • 2
    This answer seems out of date. I get: "WARNING: 'git lfs clone' is deprecated and will not be updated with new flags from 'git clone'" - is there a way to exclude with normal `git clone` ? – f1lt3r Apr 04 '19 at 21:26
  • 7
    You can do it like this: `git clone --config lfs.fetchinclude='/path/to/includes/**/*' repo.git` – Lars Schneider Sep 20 '19 at 10:29
  • Note that for `fetchinclude` and `fetchexclude`, they are now preferred to be in the `.lfsconfig` file by using `git config -f .lfsconfig lfs.fetchexclude "your_filters"` – Mark P. Jan 23 '21 at 16:35
5

if you want to ignore all git lfs files:

export GIT_LFS_SKIP_SMUDGE=1

before you clone/pull

vvvvv
  • 25,404
  • 19
  • 49
  • 81
eiTan LaVi
  • 2,901
  • 24
  • 15
0

git checkout patch (choose files to checkout)

The only way i can think of to do something like this is to use partial checkout

git checkout -p

It will allow you to choose which files will be checked out manually.

enter image description here

Ophir Yoktan
  • 8,149
  • 7
  • 58
  • 106
CodeWizard
  • 128,036
  • 21
  • 144
  • 167