0

We have a Git repository which contains a number of subdirectories:

Program /
    .git
    Package_A
    Package_B
    Package_C
        Module_A

Module_A is a dependency of our main program. The whole Module_A-folder was created and the code inside was developed in a feature branch. To this point, it is still available in the feature branch.

While developing the feature, we realized that the module is rather large and although used by our Program, it is more like an Add-on. So currently, it is included in my Program’s repository, since it is being used by it. However, in the future, we would like to implement a plugin system in our Program. Module_A will then be a plugin and does not need to be in our Program’s repository anymore.

The plugin system has not yet been implemented. Because of that, Module_A still needs to be part of the Program and cannot change its current location (Program/Package_C/ Module_A). While researching this topic, I read about submodules and subtrees. I am not sure which suits my needs, considering, that we would like to exclude Module_A fully in the future (by moving it into its own repository), once the plugin system has been implemented. Throughout this whole process of gradually moving the Module_A out of my Program’s repository, we would still like to keep the commit history.

I am unsure how the process of gradually excluding the Module_A would look. A solution that seemed good in the beginning was this one:

Detach (move) subdirectory into separate Git repository

However, this solution seems to exclude the subdirectory straight away. Right now, we would still like to have Module_A inside our Program (and keep the dependencies) but treat and handle it as its own repository (we need to be able to commit and push into both repositories separately). The above link also describes moving a directory out of a repository. Although we want to move the directory, since it already exists inside a feature branch, we were hoping to find a different solution.

The problem is hard to describe and I am unable to shorten it, but what it mostly boils down to is:

TL;DR: How can I create a new repository from an already existing feature branch, keep the inner repository inside the main repository, but be able to completely pull the inner repository out of the Program’s repository while keeping the history of the inner repository intact.

Drimer
  • 93
  • 2
  • 14
  • the approach shown is quiet interesting, maybe this in connection with `git submodules` is something worth to take a look at – Simon Schrottner Oct 19 '21 at 17:01
  • 1
    I think you're best off splitting this into two steps: First, create a new repository for Module_A with the current history, using `git subtree` or [git filter-repo](https://github.com/newren/git-filter-repo). Second, add that new repo as a submodule to the original repo. That's probably why you're struggling to describe the problem: you're trying to do too much in one go. – IMSoP Oct 19 '21 at 19:16

0 Answers0