How can I split github repo into two?

97 views Asked by At

I have github repo with 2 folders: client/server. I need to make separate repositories from these folders, but so that the commit history for each repository is not lost. After that, the main repository must be deleted. I came across the filter-repo utility on the Internet, but I didn't really figure out how it works. Could you help with that?

MAIN-REPO:

.git
  client
  server

expected result:

client:
    .git

  server:
    .git

thx!

1

There are 1 answers

0
CodeWizard On BEST ANSWER

subtree split

TL;DR;

subtree split will "split" your content into branches

Long answer

  • Split the main branch (whole content) by "folders" into branches.
  • Create submodules from the new branches (add,commit & push) into new git repo

How?

git subtree split <path> -b <branch> and then add remote for each submodule and push the branch to the remote.

# split the "main repo" into branches and preserve full history
git subtree split -P client -b <client>
git subtree split -P server -b <server>

# For each branch that you extract client/server
# create a git repo (which will be used for submodules)

# Add the content to the git server
# add remote for client
git remote add submodule1 <client_url>

# push the submodule
git push submodule1 <branch>
  • Once you have all your submodules set up add them to the "main" repo
# Add the submodules 
git submodule add <url>

Once all your submodules are added commit the .gitmodules file