Open links in new tab
  1. Merging multiple repositories into a single one while preserving commit history is useful for creating a monorepo or consolidating related projects. Below are two reliable approaches.

    Using git filter-repo (Recommended)

    This method rewrites the history of each repository so its files live in a subdirectory, then merges them.

    Steps:

    • Install git-filter-repo (if not already available):

    pip install git-filter-repo
    Copied!
    • Prepare the first repository (destination repo):

    git clone https://github.com/user/main-repo.git
    cd main-repo
    Copied!
    • Process and merge another repository:

    git clone https://github.com/user/other-repo.git
    cd other-repo
    git filter-repo --to-subdirectory-filter other-repo
    cd ../main-repo
    git remote add other ../other-repo
    git fetch other
    git merge other/main --allow-unrelated-histories -m "Merge other-repo into subdir"
    git remote remove other
    Copied!
    • Repeat step 3 for additional repositories.

    Benefit: Preserves full commit history for each file in its new subdirectory.

    Using Remote Merge with Subdirectory Move

  1. How do you merge two Git repositories? - Stack Overflow

    Sep 15, 2009 · Here are two possible solutions: Either copy repository A into a separate directory in larger project B, or (perhaps better) clone repository A into a subdirectory in project B. Then …

  2. How to combine two git repositories. · GitHub

    Dec 10, 2025 · Before starting, make sure your local and remote repositories are up-to-date with all changes you need. The following steps use the general idea of changing the remote origin …

  3. How to Merge two Git Repositories? - GeeksforGeeks

    Jul 23, 2025 · Merging two Git repositories can be a complex task, especially if they have distinct histories, branches, and commit structures. This guide explores different approaches and …

  4. How to merge two Git repositories into one (not two branches)

    Jan 27, 2024 · Merging two Git repositories can range from a simple command to a complex series of steps depending on the history and structure of your projects. By following the …

  5. Combining Two GitHub Repositories: A Step-by …

    Jun 28, 2023 · This article provides a comprehensive, step-by-step guide to integrate two repositories in a GitHub organization and also contrasts this method with using Git submodules. The need to merge repositories may arise from several situations.

  6. How to Merge Repositories in GitHub? - Life in Coding

    Nov 18, 2024 · In this blog, we will walk you through the process of merging two GitHub repositories into one, covering the necessary steps, best practices, and common pitfalls to avoid.

  7. How to Merge Repositories in Git - Delft Stack

    Mar 11, 2025 · Learn how to merge separate repositories into a master repository using Git command line. This step-by-step tutorial covers various methods for merging repositories, from direct merges to organized subdirectories.

  8. How Do You Merge Two Git Repositories? - Better …

    Jun 24, 2024 · Merging two Git repositories involves bringing the contents of one repository into another while preserving the commit history of both repositories. Here's a general approach to merge two Git repositories:

  9. How to merge multiple Git repos and keep their commit history

    Mar 18, 2023 · I wanted to merge several different repos into a single monorepo, while preserving their commit histories. Here's how I did it.

  10. How to Import an Existing Git Repository into Another as a ...

    1 day ago · Have you ever needed to combine two separate Git repositories into one, with one repo nested as a subdirectory in the other—*without losing any commit history*? Maybe you’re …

  11. People also ask
By using this site you agree to the use of cookies for analytics, personalized content, and ads.Learn more about third party cookies|Microsoft Privacy Policy