1

Scenario: In our MainProject, we have more than 12 SubProjects. Some team members works on all SubProjects, Some team members woks on 2-3 SubProjects and Some team members woks only on one SubProject.
Git Repo Strucure: We have created a main repository MainProject.git. And under it we have added different submodules for different projects, say SP1, SP2,...,SP12.

Problem: Now when any team member clones MainProject, empty directories of all SubProjects are cloned. What we want is, clone only specific submodules which are required for user and don't even want an empty folder.
How is it possible in git?

1 Answer 1

2

clone only specific submodules

This is possible. After cloning, try:

git submodule init git submodule update <path to specific submodule> 

don't even want an empty folder

I don't think this is possible since the submodule folder is a part of superProject repo.

Try git ls-files to verify this. And since we can only clone whole repository, empty folders will get created.


what if someone deleted empty folder

There are two options:

  • You can add all the submodule folders in .gitignore but that is not advisable (See Do you ignore a git submodule in your .gitignore or commit it to your repo?). The developer working on particular sub module would then have to remove the line before working on it. (Then the developers have to be careful not to push edited .gitignore, hence this doesn't solve the original problem of developers working carelessly)
  • Or, you can use pre-commit git hook to restrict people from deleting folders
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but what if someone deleted empty folder! It gets removed from server too! what can I do to restrict it?
@Tejas: there are two options, you can add all the submodule folders in .gitignore but that is not advisable (See stackoverflow.com/questions/7912022/…). You can also use pre-commit git hook to restrict people from deleting folders. If I were you I would have looked into using .gitignore
Thanks, very valuable suggestion, I recommend you to append this comment in your answer itself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.