Phriction Projects Wikis C4science Split a repository into multiple repositories History Version 4 vs 5
Version 4 vs 5
Version 4 vs 5
Content Changes
Content Changes
WARNING: Work in progress
You can use `git subtree` to extract only one part of your repository, including its history. Here's a complete example on how to create new repositories from one repository with multiple directories.
Your initial repository structure looks the schematic below. We want to split dir1, dir2 and dir3 into separate repositories.
```
myrepo
├── dir1
│ ├── myfile1
│ ├── myfile2
│ └── myfile3
├── dir2
│ ├── myfile1
│ ├── myfile2
│ ├── myfile3
│ └── myfile4
└── dir3
└── myfile
```
On your computer, create empty repositories
```
mkdir /tmp/repo-dir{1,2,3}
cd /tmp/repo-dir1; git init --bare
cd /tmp/repo-dir2; git init --bare
cd /tmp/repo-dir3; git init --bare
```
Go to the original repository and create one branch per directory you want to split
```
cd myrepo
git subtree split --prefix=dir1 -b dir1-branch
git subtree split --prefix=dir2 -b dir2-branch
git subtree split --prefix=dir3 -b dir3-branch
```
Push the branch of the original repository to the new local repositories on a new master branch
```
git push /tmp/repo-dir1 dir1-branch:master
git push /tmp/repo-dir2 dir2-branch:master
git push /tmp/repo-dir3 dir3-branch:master
```
Create the repositories on c4science, set the remote on your local repository for each new repository and push the new repositories to c4science
```
cd /tmp/repo-dir1; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
cd /tmp/repo-dir2; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
cd /tmp/repo-dir3; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
```
Deactivate the original repository on c4science and potentially [[/maniphest/task/edit/form/8/ | ask an administrator]] to remove the repository.
Enjoy your new tinier repositories :-)
You can use `git subtree` to extract only one part of your repository, including its history. Here's a complete example on how to create new repositories from one repository with multiple directories.
Your initial repository structure looks the schematic below. We want to split dir1, dir2 and dir3 into separate repositories.
```
myrepo
├── dir1
│ ├── myfile1
│ ├── myfile2
│ └── myfile3
├── dir2
│ ├── myfile1
│ ├── myfile2
│ ├── myfile3
│ └── myfile4
└── dir3
└── myfile
```
On your computer, create empty repositories
```
mkdir /tmp/repo-dir{1,2,3}
cd /tmp/repo-dir1; git init --bare
cd /tmp/repo-dir2; git init --bare
cd /tmp/repo-dir3; git init --bare
```
Go to the original repository and create one branch per directory you want to split
```
cd myrepo
git subtree split --prefix=dir1 -b dir1-branch
git subtree split --prefix=dir2 -b dir2-branch
git subtree split --prefix=dir3 -b dir3-branch
```
Push the branch of the original repository to the new local repositories on a new master branch
```
git push /tmp/repo-dir1 dir1-branch:master
git push /tmp/repo-dir2 dir2-branch:master
git push /tmp/repo-dir3 dir3-branch:master
```
Create the repositories on c4science, set the remote on your local repository for each new repository and push the new repositories to c4science
```
cd /tmp/repo-dir1; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
cd /tmp/repo-dir2; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
cd /tmp/repo-dir3; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
```
Deactivate the original repository on c4science and potentially [[/maniphest/task/edit/form/8/ | ask an administrator]] to remove the repository.
Enjoy your new tinier repositories :-)
WARNING: Work in progress
You can use `git subtree` to extract only one part of your repository, including its history. Here's a complete example on how to create new repositories from one repository with multiple directories.
Your initial repository structure looks the schematic below. We want to split dir1, dir2 and dir3 into separate repositories.
```
myrepo
├── dir1
│ ├── myfile1
│ ├── myfile2
│ └── myfile3
├── dir2
│ ├── myfile1
│ ├── myfile2
│ ├── myfile3
│ └── myfile4
└── dir3
└── myfile
```
On your computer, create empty repositories
```
mkdir /tmp/repo-dir{1,2,3}
cd /tmp/repo-dir1; git init --bare
cd /tmp/repo-dir2; git init --bare
cd /tmp/repo-dir3; git init --bare
```
Go to the original repository and create one branch per directory you want to split
```
cd myrepo
git subtree split --prefix=dir1 -b dir1-branch
git subtree split --prefix=dir2 -b dir2-branch
git subtree split --prefix=dir3 -b dir3-branch
```
Push the branch of the original repository to the new local repositories on a new master branch
```
git push /tmp/repo-dir1 dir1-branch:master
git push /tmp/repo-dir2 dir2-branch:master
git push /tmp/repo-dir3 dir3-branch:master
```
Create the repositories on c4science, set the remote on your local repository for each new repository and push the new repositories to c4science
```
cd /tmp/repo-dir1; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
cd /tmp/repo-dir2; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
cd /tmp/repo-dir3; git remote add origin ssh://git@c4science.ch/diffusion/NNNN/; git push -u origin master
```
Deactivate the original repository on c4science and potentially [[/maniphest/task/edit/form/8/ | ask an administrator]] to remove the repository.
Enjoy your new tinier repositories :-)
c4science · Help