4

I have a git project that I used for a recently published scientific paper. In the project I have subdirectories doc (split into doc/paper doc/talks) results src and more.

Now I would like to release my source code (but not my presentation slides, etc.). What is the best way to give people access to just the src subdirectory? I would release a zip file taking a snapshot of the current src directory, but I want people to get updates easily.

Thanks a lot. Oliver

user
  • 7,123
  • 7
  • 48
  • 90
  • Check out this question, which shows Howto extract a git subdirectory and make a submodule out of it: http://stackoverflow.com/questions/920165/howto-extract-a-git-subdirectory-and-make-a-submodule-out-of-it – Colin O'Dell Feb 21 '12 at 16:17

3 Answers3

6

Short version:

You need to use a separate repo per top-level folder you want to give access to. See submodules for more info on how to go about doing that.

"sparse" checkouts could work, but I believe this cannot be forced upon your users, who has to clone the entire repository to local anyway, then just get a partial working directory.

(You could also setup a separate repo that would be auto-updated and push changes to that, but you lose the opportunity to merge forks and fixes from your userbase, which is sort of the point, I guess.)

Longer version: Wo The "new" distributed version control systems (Git, Mercurial, Bazaar, etc) are not built around per-folder checkout in the same fashion as SVN and CVS. Having the branching tree separate from the directory tree simplifies handling branches and merges in the revision graph, as these are more numerous than for centralized VC:es. (SVN, IMO, handle branches & merges like a sledgehammer handles opening a can of spam, much of this is due to the fact that any directory in the hierarchy can be branched/merged).

The partial checkouts feature is easy to give in centralized scenarios where you don't branch/merge, and was therefore popular in the dawn of time. You don't get that anymore, and will probably learn to be thankful for not having it. :)

Having a few subrepos/submodules of the important stuff is therefore easier. Branching the top repo is slightly more complicated though, so you need to think about how you want to set things up to make things easy for you to work with. (Maybe releasing the presentation slides is not that bad? :)

Macke
  • 24,812
  • 7
  • 82
  • 118
  • 1
    ..." do not allow per-folder checkout like SVN and CVS did"... does not seem to be true anymore. http://stackoverflow.com/questions/180052/checkout-subdirectories-in-git. Still disagree with "This greatly simplifies...". Git is anything but simple. – AlexeiOst Dec 01 '14 at 14:51
  • @AlexeiOst: Well, you get the whole repo clone anyway. Also, Git is not simple, but I prefer Mercurial anyday (better UI, same concepts more or less). And finally, merge history tracking in SVN/CVS is magnitudes more difficult compared to Git/Mercurial and other DVCS:es. – Macke Dec 02 '14 at 07:06
4

There is no way to check out just a subfolder of a repository using git.

You could make the subfolder its own repository, or distribute tarballs/zipfiles as you suggest.

As of git 1.7, there is support for "sparse checkouts" - see here - but that's only the working copy that's sparse; you'd still have to give the users the ability to clone your whole repository.

Borealid
  • 95,191
  • 9
  • 106
  • 122
2

As stated in the Git Book under the submodules chapter, Git does not allow partial checkouts.

You may just keep as private your repository and move the development of src/ to a new, public one. Maybe on github, it has some community features -- e.g. bug tracking, follow -- that would simplify things for your followers.

Riccardo T.
  • 8,907
  • 5
  • 38
  • 78