Splitting Off a Folder Into Its Own Repo - Git
Background
¶
We had a folder on a project which contains all the front-end code. We wanted this folder to be split off into its own GitHub repo so a new front-end developer, a contractor, wouldn't have access to the back end code. This is the procedure that was done.
Reference
¶
https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository
https://docs.github.com/en/github/getting-started-with-github/splitting-a-subfolder-out-into-a-new-repository
NOTE: This article did NOT give us the desired results!
Only the "master" branch existed in the new repo
After the above issue was resolved, back end code still existed on branches besides "master".
The procedure below has been adapted to address these issues.
Procedure
¶
Sync with GitHub
Pull all commits
Commit and push all local changes
Make a full backup of the repo (optional)
GitHub
Create new repo > "MyRepo.Backup"
Git Bash
cd "/C/Users/JohnDoe/Documents/MyRepo.Backup"
git clone --bare https://github.com/soltechinc/MyRepo.git
cd "MyRepo.git"
git push --mirror https://github.com/soltechinc/MyRepo.Backup.git
Split the repo
GitHub
New repo > MyRepo.FrontEnd
Git Bash
cd "/C/Users/JohnDoe/Documents/MyRepo.FrontEnd"
git clone --bare https://github.com/soltechinc/MyRepo.git
cd "MyRepo.git"
The next step took about 14 minutes
git filter-branch --prune-empty --subdirectory-filter front-end-folder-name -- --all
git remote -v
git remote set-url origin https://github.com/soltechinc/MyRepo.FrontEnd.git
git remote -v
git push --mirror https://github.com/soltechinc/MyRepo.FrontEnd.git