Search code examples
gitgithubgitlabbitbucketgit-server

Is there a way to reverse ignore files on a git server (such as GitHub)?


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.


Solution

  • 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.