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 887069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:10:10+00:00 2026-05-15T13:10:10+00:00

I have a git repo and I want to add a submodule to it.

  • 0

I have a git repo and I want to add a submodule to it. Problem is, the submodule exists as a folder inside another repo. Can I add only that folder as a submodule?

  • 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-15T13:10:12+00:00Added an answer on May 15, 2026 at 1:10 pm

    If you really need to include part of an other repository within the history of your own repo, then the subtree merge strategy is more adequate than submodules.

    • name the other project "repo1", and fetch.
    • prepare for the later step to record the result as a merge.
    • read "main" branch of repo1 to the subdirectory "repo1".
    • record the merge result.
    • maintain the result with subsequent merges using "subtree"
    $ git remote add -f repo1 /path/to/repo1
    $ git merge -s ours --no-commit --allow-unrelated-histories repo1/main
    $ git read-tree --prefix=repo1/ -u repo1/main
    $ git commit -m "Merge repo1 as our subdirectory"
    $ git pull -s subtree repo1 main
    

    But in both case, the full repository is linked to your repo, not just one directory.
    And partial cloning is not possible.

    You could try and isolate that directory in its own repository, and then add it as a submodule, but that means its history will be totally separated from the repo its was coming from originally.

    The modern example would use git filter-repo

    cd /path/to/repo1
    git filter-repo --path repo1SubFolder
    
    #Move the files inside repo1SubFolderto the root
    git filter-repo --subdirectory-filter repo1SubFolder/
    
    # Go to your new repository, add a remote to the original repository
    cd /path/to/repo2
    git remote add repo1 /path/to/repo1
    
    # Pull files and history from this branch into repo2 
    # (containing only the directory you want to move) .
    git pull repo1 main
    git remote rm repo1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a git repo, and a revision code I want it to get
I have a git repo with a bunch of source code, and when that
git remote add joyent yourname.no.de:repo I'm assuming that this means it is using the
I have a directory tree in my repo. I do a git add -A
I have a project that I want to put onto Git. We have many
Suppose I have Git repository like this: git-repo/ directory_1/ directory_2/ directory_3/ This has a
I have a git repo which has a few branches - there's the master
I have a git repo with a dev and a master branch. Now I
So if I have a Git repo on my local machine and I send
I have machine1 with git repo client , which has branches master and fixes_v3

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.