Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
What are submodules in git?
Git allows you to include other Git repositories inside a repository called submodules. Git allows you to commit, pull and push to these repositories independently.
How does it work?
Like we have two modules A and B both have different .git files but now the requirement is to add both inside one repository but itâs not possible simply if we create one repository and push module A there then we canât push module B on the same remote URL.
But we have Submodules concept in GitHub it means we can add both repositories with different .git files inside the parent repository.
ADD multiple repositories inside a parent repository
git submodule add <git-remote-repo-url>
You can only add information about the submodule that is added to the main repository. This information describes which commit the submodule is pointing at. This way, the submoduleâs code wonât automatically be updated if the submoduleâs repository is updated. This is good because your code might not work with the latest commit of the submodule, it prevents unexpected behavior.After adding remote URLs hit below commands.
git add .git commit -m âpushed submodulesâ
Now when you start work on module A will push commits from that repository only but it wonât update the parent repository still the main repository will point to the old commit.And we canât just pull the latest commits like we normally do with a single repository.Then, how can we update the parent repository of submodules?just hit below command to update the main repository with latest commits now main repository head will point the new commit.
git submodule update
git submodule updateâââremote
How itâs helpful?
Microservices đŻ đ€Yes in terms of Microservices itâs very helpful we can add multiple services repository inside one main repository easy to manage.Microservices are still pretty popular in our industry since they imply lots of benefits. However, working with that kind of architecture might be annoying when it comes to committing the changes using GIT. Why? Simply because in a common approach, each microservice should be put in a separate repository. Therefore, instead of doing your typical âGIT sequenceâ once, you end up with few terminals where you do pretty much the same job. Fortunately, you can avoid that with no big deal.
I have created a demo repository for this on GitHub.
Thanks for reading đđ and I hope you liked this article. Donât forget to clap and follow me for upcoming articles.
Git submodules đ» was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.