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.
More details here