Reputation: 1077
My company (consultancy) is developing for another company (customer). The two main engineers on the project for the consultancy (lead iOS and lead Android) have login capabilities for the customers git for maintenance of the source code. Besides that we (consultancy) have an internal git setup for our developers to use.
To manage the internal work done it is committed to the internal git and tested and merged by one of the leads to the customers git to release source code to the client.
One project we are working on requires the use of a library which is submodule, managed by another consultancy for the customer. Our two main developers have access to this submodule as we have access to the customers git repo.
Is it possible to create a local version of the submodule on our local git for access by our other developers and maintain the git-submodule address on the external git repo?
Upvotes: 4
Views: 2856
Reputation: 5163
Is it possible to have two different submodules depending on git branch?
Ohh yes, offcourse.
The submodules in our main repo are just the commit sha id of the respective upstream repos. That said, all we need is just to initialise the two sub-modules in the main repo pointed to two different branches. Following commands should make it pretty clear:
$ git submodule add path-to-sub-module-upstream sub-module-master-directory
$ git submodule add path-to-sub-module-upstream sub-module-prod-directory
$ git config -f .gitmodules submodule.sub-module-master-directory.branch master
$ git config -f .gitmodules submodule.sub-module-prod-directory.branch production
$ git commit -m 'added two sub-modules for master and production branches'
Additionally, you can also use $ git diff --cached --submodule
to verify what is to be committed
Is it possible to create a local version of the submodule on our local git for access by our other developers and maintain the git-submodule address on the external git repo?
The submodules in many ways behave as independent projects still being part of our main repo. The development on the submodule code can take place in two simple ways which does not require us any extra command to learn
Either we checkout them independently and do all sort git commands like status, diff, branch, add, commit, pull, push...
Or we can also update the code of submodules which are part of the main repo. In the simplest way All we need to do is go inside the submodule-directory and FEEL like you are inside the independently checked out project. So, what I basically meant is as follows:
$ cd sub-module-master-directory
$ git status/diff/add/commit/push/pull #WHATEVER you can practically do inside an independently checkout project
Post that we can go to the main repo directory and commit/push the latest references of our sub-module repo. Or if you want to go fancy about it, then create a post-commit/push hook for the submodule which automatically update the references of the sub-module commits on the main repo.
Upvotes: 1
Reputation: 142164
Is it possible to create a local version of the submodule on our local git for access by our other developers and maintain the git-submodule address on the external git repo?
This is one of the reasons why to use submodules. git submodule
is a standalone git repo contained in another git repo.
From the doc:
Submodules
allow foreign repositories to be embedded within a dedicated subdirectory of the source tree, always pointed at a particular commit.
As explained above the submodule content is fetched form a standalone repository to a folder inside your current repository. Any modification to the submodule folder will not appear in the root folder git status
on the root folder will not display them.
So to summarize it: submodule is exactly what you need here.
Upvotes: 3