Since i am at the very beginning of the Git learning curve i have tendency to screw things up. As an example, i recently created a repository for couple of the unrelated projects. It would be ok when the projects are in the CVS or SNV repositories but it is apparently quite different with Git.
Since, client downloads the whole repository i ended up with the number unnecessary projects downloaded to the CI building server. Obviously, it is not the end of the world, but definitely is not way to go. And since i am learning i want to do things right way.
So, the idea was to extract projects from the one large "common" repository and place them into their own respective repositories keeping the commit history for the files that are being stored in the new repository.
Here is the sequence of steps that i had to do. So, let's imagine that the old "common" repository resides on the server server.local in the /home/git/repository directory. The idea is to extract three project from this repository (project1, project2, and project3) and place them into their own respective repositories on the same server located at /home/git/project1.git, /home/git/project2.git and /home/git/project3.git respectively.
1. On the server side create bare repository for the new project:
mkdir /home/git/project1.git
cd /home/git/project1.git
git --bare init
2. On the client side, clone the old repository to the working directory:
git clone ssh://server.local/home/git/repository
This will create a repository sub-directory in my working directory.
3. Next, disconnect the local repository from its remote parent by deleting the remote repository definition:
cd repository
git remote rm origin
4. Remove everything that does not belong to project1 directory:
git filter-branch --subdirectory-filter project1 -- --all
Now, all the files belonging to the project1 are in the root directory of the repository.
5. Move all the files into the project directory project1:
mkdir project1
mv * .[^.]* project1
mv project1/.git ./
6. Add new files to the got repository:
git add --all .
7. Commit the changes:
git commit -m "Initial commit"
8. Add new remote server:
git remote add dest ssh://user@server.local/home/git/project1.git
9. Push changes to the remote server
git push dest master
10. Disconnect the remote repository
git remote rm dest
That is it.