9

I have a git repo which has some subdirectories:

~/src
~/src/.git
~/src/mystuff
~/src/otherstuff

Now I want to share src/otherstuff with someone else. They should be able to clone it and push changes in otherstuff, but I don't want them to be able to access src, commits in mystuff nor even see that they exist.

How do you go about this with git?

wim
  • 338,267
  • 99
  • 616
  • 750
  • 1
    What about using two repos, one a submodule in the other? – Eric Walker Mar 12 '13 at 05:21
  • 2
    Yes, what about it? What does it mean, how do I do it, etc. – wim Mar 12 '13 at 05:22
  • 1
    See here: [git submodule](http://git-scm.com/book/en/Git-Tools-Submodules) – Santa Mar 12 '13 at 05:25
  • I was already reading that page, actually, but I don't understand the differences with `git-subtree`. It also seems to be geared towards adding in some other pre-existing git repo to my own, which is different from my situation – wim Mar 12 '13 at 05:33
  • 3
    Well, your situation is using git in a way it is not intended. :) What happens to revisions that only affect "mystuff", or revisions that affect "mystuff" and "otherstuff" in the same commit? You can't just rip a git repo in half and expect it to be happy. Submodules are for joining external repos together, like svn:externals. – Nick Veys Mar 12 '13 at 05:38
  • 2
    Would something like this work? http://stackoverflow.com/questions/1662753/export-subtree-in-git-with-history or do you want to actually keep this repo in one piece but still share just that subdirectory? – Nick Veys Mar 12 '13 at 05:40
  • Hmm. Good point. Actually, I don't mind if revisions that change `mystuff` and `otherstuff` in the same commit were prohibited. But maybe what I had in mind isn't possible, I would be open to other suggestions including changes to my workflow .. – wim Mar 12 '13 at 05:43

1 Answers1

12

Making a git init within a git repo works: the directory in which you init the nested repo simply becomes ignored by the parent repo.

However, if the history of that subdirectory is important, is is best to export it as a separate repo (as Nick suggested).
From there, you can keep both repos in lock steps by declaring that new repo as a submodule of the parent repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250