My requirement: Break down one git repo, into multiple git repos, preserving the same directory structure as in the original repo, and preserve the commit history for the files that are copied to the new repo.
What I have tried already:
Here is what worked for me(combining answers from @AD7six and @Olivier) to split my
orig-repo into multiple new repos. I'm listing here steps for creating only one new repo
new-repo1. But same have been used to create the others as well.
First create new empty repo on Github with the name
git clone [Github url of orig-repo] git clone --no-hardlinks orig-repo new-repo1 cd new-repo1 git remote rm origin git checkout -b master //This step can be skipped. I had to do it since the default branch on my orig-repo was `develop`, but on the new-repo1 I wanted to create it as `master` //I used a script here to delete files and directories not required in the new-repo1. //But if you have very few files/dirs to be deleted then you can do the below. git rm <path of file 1 to be deleted> git rm <path of file 2 to be deleted> git rm -rf <path of dir 1 to be deleted> git commit -m "Deleted non-new-repo1 code" git ls-files > keep-these.txt git filter-branch --force --index-filter "git rm --ignore-unmatch --cached -qr . ; cat $PWD/keep-these.txt | xargs git reset -q \$GIT_COMMIT --" --prune-empty --tag-name-filter cat -- --all rm -rf .git/refs/original/ git reflog expire --expire=now --all git gc --prune=now git init git remote add origin [Github url of new-repo1] git push -u origin master
After this, I can view history of files in the
new-repo1 on Github as well as through command line using