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/.

  • How to remove a dangling commit from GitHub?
  • Can I use ksdiff over ssh?
  • Why is “origin/HEAD” shown when running “git branch -r”?
  • In git, is there a simple way of introducing an unrelated branch to a repository?
  • How to include project on git into new android project
  • How to get a human-readable dump of .git/index?
  • 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/
      else
        url = H:/gitrepos/subsystem1.git/
    

  • Git for windows paging
  • Can I view Git commit history in Visual Studio 2013 for TFS Git VC before cloning?
  • How to solve a revert commit conflict
  • Reuse a Part of a git Repository
  • How does CocoaPods work
  • Remove a directory from git locally
  • 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:

    /mnt/gitrepos/
    /mnt/gitrepos/subsystem1.git/
    /mnt/subsystem1.git/
    

    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.