git splitting repository by subfolder and retain all old branches

Viewed 8519

I have a git repo with 2 directories and multiple branches, I want to split them and create all branches

`-- Big-repo
    |-- dir1
    `-- dir2

Branches : branch1, branch2, branch3 ...

What I want

I want to split dir1 and dir2 as two separate repos and retain branches branch1, branch2 ... in both repositories.

dir1
Branches : branch1, branch2, branch3 ...

dir2
Branches : branch1, branch2, branch3 ...

What I tried:

I am able to split them into 2 repos using

git subtree split -P dir1 -b dir1-only 
git subtree split -P dir2 -b dir2-only 

But, it is not creating any branches after separation.

To get all branches:

git checkout branch1 (in Big-repo)
git subtree split -p dir1 -b dir1-branch1

git checkout branch2 (in Big-repo)
git subtree split -p dir1 -b dir1-branch2

And push these branches to newly created repo.

This involves more manual effort and I am sure there might be a quick way to achieve this?

Any ideas???

2 Answers
Related