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 cherry pick - range of commits and exclude some in between
  • What are the three files in a 3-way merge for interactive rebasing using git and meld?
  • Why isn't Git listening to my working tree argument?
  • git version control with local files
  • In gitk, why is my yellow button above master?
  • Git repository on ftp server
  • bitbucket git push authentication failed (mac os x)
  • Option to push disabled in Visual Studio Code
  • Error occurred while installing openstack : ./stack.sh:137:die
  • Git - get a list of files that are identical between two revisions
  • git pre-commit + mysqldump: cannot find path, not existing command
  • Splitting one commit into 2 and get the resulting diff
  • 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.