GIT Splitting a subfolder out into a new repository

From Luniwiki
Jump to: navigation, search

Create a new repository

See GIT_repository_on_Ubuntu#Create_repository to create the new repository.

Clone the actual repository

git clone https://<USER>@git.luniel.com/git/<REPOSITORY> <LOCAL_FOLDER>

i.e.:

git clone https://daniel@git.luniel.com/git/BIGRepo.git BIGRepo

Filter only the folder

cd <REPOSITORY>
git filter-branch --prune-empty --subdirectory-filter <REMOTE_FOLDER> <BRANCH>

i.e.:

cd BIGRepo/
git filter-branch --prune-empty --subdirectory-filter LittleFolder master

Change origin to new repository

git remote set-url origin https://<USER>@git.luniel.com/git/<NEW_REPOSITORY>

i.e.:

git remote -v
origin  https://dsimao@git.luniel.com/git/BIGRepo.git (fetch)
origin  https://dsimao@git.luniel.com/git/BIGRepo.git (push)
git remote set-url origin https://daniel@git.luniel.com/git/LITTLERepo.git
git remote -v
origin  https://daniel@git.luniel.com/git/LITTLERepo.git (fetch)
origin  https://daniel@git.luniel.com/git/LITTLERepo.git (push)

Push the split folder to the new repository

git push -u origin <BRANCH>

i.e.:

git push -u origin master               
Password for 'https://daniel@git.luniel.com':
Counting objects: 3385, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2703/2703), done.
Writing objects: 100% (3385/3385), 7.43 MiB | 51.05 MiB/s, done.
Total 3385 (delta 691), reused 3130 (delta 617)
remote: Resolving deltas: 100% (691/691), done.
To https://git.luniel.com/git/LITTLERepo.git
 * [new branch]        master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

References

Daniel Simao (talk) 13:55, 8 February 2019 (EST)