Page MenuHomec4science
Contents

Split a repository into multiple repositories
Updated 2,249 Days AgoPublic

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

GIT

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.

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 with 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 ask an administrator to remove the repository.

You can now remove the temporary bare repositories (/tmp/repo-dir1, /tmp/repo-dir2, /tmp/repo-dir3) and clone them from c4science.

Enjoy your new tinier repositories :-)

SVN

You have two solutions,

  1. Contact the administrator and ask for a specific split solution (which directories goes where) and we will do it for you
  2. Migrate your repository to GIT and split it yourself at the same time

Here's how to migrate your repository from SVN to GIT,

  • Get a specific directory (dir1, ...) of your SVN repository and check it out as GIT:
cd /tmp
git svn clone svn+ssh://git@c4science.ch/diffusion/XXX/dir1
cd dir1
git remote add origin ssh://git@c4science.ch/diffusion/YYYY/
git push -u origin master

And voila, ask the c4science admin to remove your old SVN repository

Last Author
aubort
Last Edited
Sep 24 2018, 14:08

Event Timeline

aubort created this document.Jan 29 2018, 16:41
aubort edited the content of this document. (Show Details)
aubort added a project: c4science.
aubort edited the content of this document. (Show Details)Jan 31 2018, 11:27
aubort edited the content of this document. (Show Details)Jan 31 2018, 11:29
aubort edited the content of this document. (Show Details)Jan 31 2018, 11:37
aubort edited the content of this document. (Show Details)Jul 2 2018, 16:08
aubort edited the content of this document. (Show Details)Jul 9 2018, 13:22
aubort edited the content of this document. (Show Details)Jul 9 2018, 13:39
aubort edited the content of this document. (Show Details)
aubort edited the content of this document. (Show Details)Sep 24 2018, 14:08