How to exclude a folder to be downloaded when hosting R package in github

I asked this question in stackoverflow but didn't see enough discussion. I have managed to work around the problem but still wondering if there is any better solution.

My package is hosted in github, and user can install it through devtools::install_github.

I'm using pkgdown to generate documentation site, which created a 10M docs folder. Then I found devtools::install_github always download the whole master zip ball which become quite slow.

I tried to exclude the docs folder with these attempts:

  1. .Rbuildignore, turned out it's only about bundled package, while install_github is installing source package so it doesn't work.
  2. put package one level lower than root folder.
    root/pkg: package source
    root/docs: package site
    However the whole master zip ball is always downloaded, even with subdir = "pkg" specified.
  3. put full package source and generated site in a branch package, and to exclude docs folder from the master branch. Developing in package branch, update site, but keep site out of the master branch. This means I need to merge two branch except docs folder. I tried make .gitignore to be branch specific but it doesn't seem to work. This seemed to be impossible.
  4. My newest attempt is to create a separate repo solely for the website, just let pkgdown create the website in that folder like build_site(path = "../docsite/docs"). This solved the problem and everything is simple. The only imperfection is the website url will not be the usually pattern.

EDIT: made some edits to clarify.

You might try serving the site from the gh-pages branch rather than from the docs/ directory. pkgdown does not support this out of the box but it should be possible to do with a little work.

If I'm understanding correctly, this seemed to be just the 3rd approach I tried in the original question. I edited the post a little bit to make it more clear.

My goal is to exclude docs from source package unless there is other method to reduce download size.

So if I put pkgdown generated docs in a separate branch like gh-pages, that means

  1. gh-pages branch need to have source folders so pkgdown can generate site from them.
  2. I need to merge master into gh-pages branch from time to time before updating the site.
  3. Since master don't have docs folder, it has to be ignored in .gitignore.
  4. git doesn't allow branch specific .gitignore, so docs folder is also ignored in gh-pages branch. That means my local generated docs folder will not be pushed into github server, thus no site served.