What is Git?
Git is a free and open source distribution for the management of software or program’s version. Alternative to svn, which is also a version control system.
How Git Works?
Git creates a bunch of trees, blobs, etc from your code And assigns hash value to of them. Now it internally checks the hash values of the created items with your code to determine the changes in your code. Overall it means detecting the versions.
What is Git Submodule?
A Git submodule is also a git repository but this time the repository is external repository. In other words, A git submodule is a record within a host git repository that points to a specific commit in another external repository.
Why Git Submodule?
Imagine you are developing a microservice application, which consists of multiple applications. Now there are certain files that are the same and used by one or much microservice application. In this case, you can bundle up the shared codes to a new repository and all other microservices can just use the git submodule to get the codes. And the biggest benefit is that if you want to change anything then just make changes in the shared repository and all other microservices can just update the submodule and will get the latest and updated code.
Command to add Git Submodule
git submodule add <Repository_Path>
Command to update the submodule from the remote
git submodule update --remote
Limitation of Git Submodule
You will not able to track the changes in the git submodule.
But that’s totally fine. You are using the submodule for the shared codes, which are just like a library codes. Your submodules Host repository is already tracking the changes and it has all the records.
I personally uses the git submodule a lot and it is super useful.