SoftTimur SoftTimur - 1 month ago 9
Git Question

Invite different collaborators to different subfolders of a repository

I have bought a

personal user account
of github.

For example, I have created a repository
repo
, and it has two subfolders:
app1
,
app2
.

Does anyone know if it is possible to invite
collaborator1
for the
app1
subfolder, and invite
collaborator2
for the
app2
subfolder.

If this is impossible with
personal user account
, does
organisation account
permit this?

PS: I have some other files (eg,
test.sh
) under
repo
that use both
app1
and
app2
, so if I create two separate repositories for
app1
and
app2
(rather than an entire
repo
), I will not be able to put those test files in git.

Answer

This seems like a good case for git submodules.

As lest mentioned, you'll first need to create separate repositories for app1 and app2. These are entirely independent and don't know about each other, you therefore can have separate permissions.

You can then add app1 and app2 as submodules, in the repo repository.

In repo repository, remove the app1 and app2 directories (after creating their respective repos, of course) and run:

git submodule add git@github.com/username/app1
git submodule add git@github.com/username/app2

These two repositories will be added as directories in the root of the repo repository and will be tracked in the newly created .gitmodules file. The tests scripts will not have to be changed as they will just see the directories as normal.

Users can checkout app1 and app2 as independent repositories, but you can also get all the code with the following:

git clone --recursive git@github.com/username/repo

Or if you already have repo cloned you can update the submodules using:

git submodule update --init

For more information, consult the git submodule documentation.

Comments