BitBucket - Create repository and sub modules

Jatin picture Jatin · Mar 31, 2016 · Viewed 16.7k times · Source

I am using bitbucket web interface and have created a new project "Test_Project". In this project, I am able to create a new repository - 'Module1' using Create repository option.

Now I want to create repository hierarchy in bitbucket project - Test_Project as following :-

Test_Project (Bitbucket project)

  • Web (Repository 1)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • Mobile (Repository 2)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • Archive (Repository 3)

     Module1 (Sub-Repository/Sub-module 1)
     Module2 (Sub-Repository/Sub-module 2)
     Module3 (Sub-Repository/Sub-module 3)
    
  • Project Documents (Repository 4)

    And so on..

So that I will add the local projects in respective bitbucket sub repositories

Can anyone please guide how to create the sub-repositories/sub-modules in new repository in bitbucket.

Answer

CodeWizard picture CodeWizard · Mar 31, 2016

You simply need to be in your root folder and then add the submodule folder.

git submodule add <url>

Now when you clone the project you simply need to init and update the submodule

git submodule init
git submodule update

Git 1.8.2 features a new option --remote

git submodule update --remote --merge

will fetch the latest changes from upstream in each submodule, merge them in, and check out the latest revision of the submodule. As the docs put it:

--remote

This option is only valid for the update command. Instead of using the superproject’s recorded SHA-1 to update the submodule, use the status of the submodule’s remote-tracking branch.

This is equivalent to running git pull in each submodule.


Git 2.8 update

Parallel fetches of submodules

Using git submodules, one Git repository can include other Git repositories as subdirectories1. This can be a useful way to include libraries or other external dependencies into your main project. The top-level repository specifies which submodules it wants to include, and which version of each submodule.

When you fetch into the top-level repository, you typically want to fetch into the submodule repositories as well:

git fetch --recurse-submodules

If you have a lot of submodules, all of these fetches can be time-consuming; git fetch is essentially run in each submodule in turn.

But now you can speed things up by fetching from multiple submodules in parallel. For example,

git fetch --recurse-submodules --jobs=4