0

Question

Is there a way to define patterns to not pull files from the git server on a git clone or git fetch? This may be called a "reverse git ignore".

Problem

What I have is a repository of dotfiles and I want to have a readme in the root of the project that is named README.md. With this file GitHub can display it with nice formatting.

As the repo is to be checked out in the user's home folder on a *NIX machine, all the dotfiles will be hidden as intended, but the README.md will not and that is not desired.

So I do not want the README.md to be pulled when the repo is cloned. How to achieve that?

Alternative solution

If the above desired result is not possible, can the README.md be hidden or obscured in the home folder through some other method?

Example of problem

If it helps, here is the dotfiles repository I am working on.

2 Answers2

0

Yes there is a way to create a partial clone. You have to clone in a special way, providing a filter-spec so git knows what files to fetch and which ones to ignore.

You can find all about it in the docs. https://git-scm.com/docs/partial-clone

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Thanks for the answer. I did not know about partial-clone. It is interesting. It seems to be intended for omitting large files. Based on [this answer](https://stackoverflow.com/questions/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository/52269934#52269934) I come to the conclusion that it is a bit too cumbersome to do this every time I want to clone the repo. I also did not manage to get it to work yet. So I will work around the problem by not having a README in the root directory. –  Jul 12 '21 at 14:06
  • You can use partial clones for large files or grabbing a single set of projects from a big mono-repo... Or to leave out Readme.md :). If your users need to run a command to clone the repo to r specific location anyway, you could easily have that command or script delete the readme.md after fetching the files. – jessehouwing Jul 12 '21 at 14:23
0

While it is possible to not download files with partial clone, those files will be implicitly downloaded once the working tree is checked out. If your goal is to ignore certain files for a dotfiles repository, you have some options:

  • Design the repository such that it is not checked out directly into the user's home directory, but into some other directory, and use a script to copy files into place. This is generally the recommended approach.
  • Mark README.md as export-ignore in .gitattributes and use git archive to copy the files into place.
  • Use sparse checkout to exclude the README.md from checkout. See git-sparse-checkout(1) for more details.
  • Live with the extraneous README.md file.
bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thanks for providing several options that are relatively easy to implement. After going over the options I decided to stick with having the README.md outside the home folder. I am considering to move to the recommended approach of copying files into home folder. –  Jul 13 '21 at 14:07