Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3322226
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:09:24+00:00 2026-05-17T23:09:24+00:00

I have a project in Git that has several submodules, and I need those

  • 0

I have a project in Git that has several submodules, and I need those submodules to be downloaded and the files available in order to use the main project, and in order for the submodules to work I need their own submodules to be available etc. So to set this up I recursively initialise the submodules using git submodule update --init --recursive.

However, I’ve noticed that many of my submodules have shared dependencies, looking something like this in pseudocode (alpha -> beta represents that alpha has the submodule beta)

my project -> submodule a -> submodule m
           -> submodule b -> submodule m
                          -> submodule n -> submodule x
           -> submodule c -> submodule x

My question is: is there any way of avoiding this duplication using only git, while still having (at least one copy of) the files for each submodule?

I can imagine a solution with symlinks, but it would be preferable if git handled this for me, and I’m not sure whether putting in the symlinks myself would cause problems when updating the submodules.

Ideally I’d love to simplify it down to:

my project -> submodule a -> symlink(submodule m)
           -> submodule b -> symlink(submodule m)
                          -> symlink(submodule n)
           -> submodule c -> symlink(submodule x)
           -> submodule m
           -> submodule n -> symlink(submodule x)
           -> submodule x

Thanks in advance for any suggestions!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:09:25+00:00Added an answer on May 17, 2026 at 11:09 pm

    This isn’t built into git, but you can definitely do it with symlinks like you say. You might want to have a look at git new-workdir (from git’s contrib directory), which does essentially this. It’s not aware of anything to do with submodules, but a submodule doesn’t know it’s a submodule – it’s the parent repo that knows about that stuff. I haven’t tried this, but I’m fairly certain you could use it something like this:

    # remove the target first (new-workdir will refuse to overwrite)
    rm -rf submodule_b/submodule_m
    
    #               (original repo)         (symlinked repo)
    git new-workdir submodule_a/submodule_m submodule_b/submodule_m
    

    It works by symlinking essentially all of the .git directory; the notable thing that isn’t symlinked is HEAD; the two directories can have different things checked out, but share the same refs and objects.

    From here you should be good. When you run a git submodule command in the supermodule, it just goes into the submodules and runs appropriate commands there, which will all work as expected.

    The one thing you usually need to be aware of with symlinked repos like this is that they share the same set of branches, so if they both have the same branch checked out, and you commit to it in one, the other will become out of sync. With submodules this generally won’t be a problem, though, since they’re essentially always in detached HEAD state unless you intervene.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I've got a project under git version control. Within that project, I have
So I have a Git project, and we (a mostly typical Rails project) have
I have a project hosted on git.debian.org (alioth) and I'd like to configure a
I have project on github.com. All summer i made commits. Now i need to
I currently have a single solution that contains both the one application developed so
We're a small software company that has been using CVS and SVN for version
I have a directory that looks like this: ProjectFolder/ + project_file + project_file_2 +
I have a few questions about git. I have read a couple of documents
My colleague pointed out lately, that SVN refers to its commits with unique numbers.
Let's say I have this dir structure: /project1 /SomeFolder /obj /bin /project2 /obj /bin

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.