Git submodule for Linux and Windows

When using git submodule on Linux I might have a .gitmodules with one or more subsystems checked out from e.g. /mnt/gitrepos/subsystem1.git (central file based access).

[submodule "subsystem1"]
  path = subsystem11
  url = /mnt/gitrepos/subsystem1.git/

I would like to support also a Windows user who can access the same module repo from H:/gitrepos/subsystem1.git/.

  • using git in a production server
  • How can I tell whether the current working directory is ignored by Git?
  • GitHub: How to do case sensitive search for the code in repository?
  • git: Log for 'master' only goes back to date bug?
  • Locking binary files using git version control system
  • Why does cherry-pick tell me that I have all lines changed?
  • It is e.g. a Samba share from Linux of /mnt/gitrepos/ as the share gitrepos.

    Is there a way where Git can handle the URL line depending on the OS?
    For Windows the .gitmodules would be

    [submodule "subsystem1"]
      path = subsystem11
      url = H:/gitrepos/subsystem1.git/

    Thus I would like “something like” this generic code for .gitmodules (speculative syntax):

    [submodule "subsystem1"]
      path = subsystem11
      if Linux 
        url = /mnt/gitrepos/subsystem1.git/
        url = H:/gitrepos/subsystem1.git/

  • How to exclude files from a pull request?
  • Know when a line of code was added to a GitHub repository
  • How do you use Git to retrieve just one (or a few) files from a repo?
  • Git clone particular version of remote repository
  • Pushing local repository to server
  • How can I display output in a pager after a git command?
  • 2 Solutions collect form web for “Git submodule for Linux and Windows”

    No. Submodules are generally designed for one repository URL that works everywhere, usually network-based (e.g. git://host/path). There is no mechanism for providing multiple different URLs for one repository.

    That said, Git does allow you to customize a submodule’s URL. When submodules are initialized (git submodule init), the URL from .gitmodules is copied to your .git/config file. You can now edit the URLs there before running git submodule update.

    One workaround I’ve considered (but not tried) is to initialize the submodule codebase (“subsystem1.git” in your example) as an independent, local repository. Add a “remote” in the submodule which points to the independent, local version of the repository. Also add a “remote” in the non-submodule (indepent, local) version of your subsystem repository which points to the submodule version. You should then be able to use Samba / Windows / Linux to update the independent (non-submodule) version of subsystem1.git, and then “git fetch independent” from within the submodule to copy the code from the non-submodule repository to the submodule repository.

    At the end, your directory structure should look something like:


    The remotes in each of these repositories would look like the following:

    /mnt/gitrepos/.git/config would have one remote block:
        [remote "origin"]   (points to your main, non-local repository)
    /mnt/subsystem1.git/.git/config would have two remote blocks:
        [remote "origin"]   (points to your main, non-local repository)
        [remote "local_origin"]   (points to /mnt/gitrepos/subsystem1.git)
    /mnt/gitrepos/.git/modules/subsystem1.git/config would also have two remote blocks:
        [remote "origin"]   (points to your main, non-local repository)
        [remote "independent"]   (points to /mnt/subsystem1.git)

    Synchronizing your submodule’s code with what’s on the remote server then becomes a multi-step process, since you have to use the “independent” repository as an intermediate repository / staging area.

    Your Mileage May Vary… This is just a thing that seems like it should work, not something I’ve tried.

    Git Baby is a git and github fan, let's start git clone.