Search code examples
gitgit-submodulesgit-cherry-pick

Convert Git subdirectories into submodules


Using Windows for development, Debian for servers and repos, Git Extensions as Git client.

I have the following repos:

REPO1:

ROOT_OF_SITE1/

REPO2:

ROOT/
    /SITE1/
    /SITE2/
    /SITE3/

SITE2 and SITE1 share the same code base, just SITE1 is a few commits ahead, but since the path is different can not cherry pick commits from SITE1 from REPO1 to SITE1 in REPO2.

I suppose one of the solutions is to convert SITE2 subdirectory to Git submodule, so then I could cherry pick commits from SITE1.

However each time I use git submodules, I'm facing problems in Git Extensions.

Unfortunately the Git Extensions Git client does not support subtree at this time.


Solution

  • I would use one repo with SITE1 and I would split the rest of sites using git subtree. You can divide your repo in different branches, keeping several modules organized with a quite clean tree:

    git subtree split --prefix=site2 -b site2
    

    Check this post for further information. You can then build the tree back leaving a really nice git history.