Git pull ignore image files

I’m a contributor on a repository that occasionally has images posted to it. The images are really not essential, but the other contributors will continue to add and push them to the repository. I would like to perform pull operations that ignore image file suffixes, such as *.png. The git directory is just taking up too much space, and I really don’t need to be pulling these image files.

How can I not pull the image files, but get everything else?

  • git aws.push: 'aws.push' is not a git command
  • How to solve'fatal: index-pack failed'?
  • What does “You are in the middle of an am session” mean?
  • RStudio: git add --all from the UI
  • Git log: fatal object is corrupted
  • Git pulls a push.default warning
  • Checkout git repo with chef with ssh key
  • How do I “undo” a --single-branch clone?
  • How to add a file to the last commit in git?
  • Aborting `git stash apply`
  • show all tags in git log
  • How to Prevent Garbage Collection in GIT?
  • One Solution collect form web for “Git pull ignore image files”

    You can use sparse-checkout to sparsly populate your working directory. sparse-checkout makes use of the skip-worktree bit which makes git assume that the file in your working tree is up to date no matter what.


    For the following I’ll assume that you are currently in the root of your repository and have a clean working tree (git stash e.g.).

    First you have to enable sparse-checkout using git config core.sparsecheckout true; after this you can define all patterns you want to “ignore” on checkout in .git/info/sparse-checkout.
    The syntax is the same as in a .gitignore file, the difference being that you define all files you want to checkout not the ones you want to ignore.

    Let’s assume you want to avoid checking out all png files in your repository, then your sparse-checkout file could look like this:

    *         # Include everything
    !*.png    # Flag png files with the 'skip-worktree' bit
    

    If you want to apply the sparse-checkout to your current working directory you have to execute a read-tree command afterwards.

    git read-tree -m -u HEAD
    

    After that you can continue working with your repository as usual, without the “ignored” files in your working tree.


    TL;DR:

    • Activate sparse-checkout: git config core.sparsecheckout true
    • Define a sparse-checkout file under .git/info/ containing the patterns of files you want to include
    • Update your working tree git read-tree -m -u HEAD

    You can read more on sparse-checkout in the official documentation of git read-tree.

    Git Baby is a git and github fan, let's start git clone.