Add submodules in an existing/new project.
Git submodules are a feature in Git that enables you to include another Git repository within your main repository as a subdirectory. This is particularly useful when you want to integrate an external project into your own codebase as a reusable component. With submodules, you can maintain separate version control for each component, allowing independent development while still keeping the main project up-to-date with the latest changes in the submodules.
Step-1: Create your repository (Ignore this step if you already have one odoo-sh project)
- Go to your Github Account My Github Account
- Make sure you are logged in.
- To create a new repository, click on the "New" button in the left side bar or you can directly go to Create New Repository
- Now you will be redirect to the page of repository creation.
- You can now add the basic data. You can choose the base Repository Template if you need, choose the Owner as "blooparksystems", add your Repository Name, add a short Description, and make your repository as either Public or Private. It's your choice. And then click on "Create repository".
- Good Job.!, Now you created your project repository. 👏👏 .. The first step is done.
Step-2: Add submodules in Odoo-sh Project.
- Go to your odoo-sh project or create new if you don't have one.
- If your odoo-sh project is new, create main-staging and main-development branches if needed.
- Create a new branch from either development branch or the branch you are going to merge this submodule.
- We can directly add the submodule to main-development branch. but I will not recommend. Always good to track all the features that we are adding as a separate branch. :)
- Now we are going to add the submodule, before adding a submodule, it's good to check the submodule is a private or public repository. If it is a private repository, then we should add the submodule in odoo-sh project.
- If it's a private repository, let's first copy the SSH URL from the github project repository.
- For example, if you want to add BOM-PACK submodule to this project, goto the repository and copy the SSH URL
- Now, Go to Odoo-sh project settings ==> submodules.
- Add your submodule SSH URL here and click on "Add" button. These settings are required only for the private repositories.
- Now a Public Key will be generated and copy this key.
- The copied key should add inside the submodule github repository. Our submodule here is addons-bom-pack.
- If you ignore the above step, then your build will be definitely fail.
- Now, Go to your Odoo-SH project, select the branch, On the top right corner, click on "Submodules" and then click on "Run On Odoo.sh".
- This will now open a wizard to enter the submodule details.
- Copy the submodule SSH URL.
- This SSH URL will be the "Repository URL" and choose the correct branch to add. Path you can add any, but default will be "blooparksystems/repositoryname"
- Then click on "Add Submodule".
- You are almost Done. Now, wait for the build to complete. 👏 👏
ADD SUBMODULES VIA TERMINAL
- You can add your submodules through the terminal as well. Go to your project from the terminal.
- Checkout to your branch.
- Run the command below
git submodule add -b branch --depth 1 submodule_SSH_URL directory_in_project/submodule_name
where,
branch: the branch of submodule you wish to add.
submodule_SSH_URL: SSH URL copied from github repository (git@github.com:blooparksystems/addons-bom-pack.git)
directory_in_project: While creation of the repository, if you selected the "Repository Template", then some folders are already be there for adding submodules. You can choose either addons_repos_ext or create a new directory and apply here.
For example:
git submodule add -b 16.0 --depth 1 git@github.com:blooparksystems/addons-bom-pack.git addons_repos_ext/addons-bom-pack
After running the above command, make sure this submodule is automatically added in .gitmodules file.
Also add this submodule path in config file and docker-compose.yml file (This is completely optional)
Perfect, Now you are good to go, add these changes to the project, commit and then push to your repository.
After testing this submodule workflow in your featured branch, you can merge these changes to your base branch.