Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull ignore image files

Tags:

git

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?

like image 548
nick_name Avatar asked Dec 11 '14 05:12

nick_name


1 Answers

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.

like image 160
Sascha Wolf Avatar answered Sep 28 '22 15:09

Sascha Wolf