Referring to the same submodule twice

I have two code libraries A and B and have started developing an application M.
All three of these are stored in their own repository.

My problem is that I have a dependency such that A uses submodule B, but M uses both submodules A and B.

  • Can I use command-line Git tools and TortoiseGit simultaneously?
  • Dealing with git, generated files and bower
  • Git/GitHub connection issue on VM/VirtualBox
  • Bitbucket: Conflict in remote repo, can't figure out how to resolve
  • Jenkins unable to fetch repo - code 255 permission denied
  • heroku console show the latest sha hash from git deployment
  • As far as I can tell I’ll have two copies of the same submodule B for the same main project. But it would never make sense (in this setup) for them to be different, as they represent the same library in the same application.

    Is there a way to work around this, so that when I work on M I have only one copy of A and B?

  • How to substitute text from files in git history?
  • Automatically synchronizing a Subversion repository and a Git repository
  • Xcode 4 Git—“This file does not exist at the requested revision”
  • How do I get `git clone --recursive` to recreate submodules' remotes and branches?
  • Migrating Mercurial to GitHub
  • Git rebase --continue complains even when all merge conflicts have been resolved
  • 2 Solutions collect form web for “Referring to the same submodule twice”

    M--/
       |-- A
       |   |-- B
       |
       |-- B
    

    Just remove M/B submodule from M, and keep/use M/A/B.

    The reasons:

    1. For A submodule(a independent repository), it must needs B for something.
    2. For M repository, you can teach it to use M/A/B.

    As i understand in your app M hierarсhy is something like this:

    M /
      |- A /
           |- B
    

    So to add submodule B to A you should do (in folder A)

    git submodule add git@github.com:username/B.git
    

    For the app M you should do the same but with path to existing B (in folder M)

    git submodule add git@github.com:username/B.git A/B
    
    Git Baby is a git and github fan, let's start git clone.