gitgit-submodulesgit-subtree

git init in a git subdirectory


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?


Solution

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