How to split a git repository

This page explains how to permanently split a git repository on Unix. It uses a simple dummy directory to show the process.

First, from the Unix command line, create a dummy repository containing two files:

mkdir dummy
cd dummy
echo "dummy.1" > dummy.1
echo "dummy.2" > dummy.2
git init
git add .
git commit -a -m "Initial commit"

(download)

You are now in the directory "dummy" and there are two files, "dummy.1" and "dummy.2", containing their own names. Now go up to the parent directory, and use git clone to clone the "dummy" repository into another repository:

cd ..
git clone dummy split

(download)

We only want "dummy.1" in repository "dummy", and we only want "dummy.2" in repository "split", so we remove the files, and commit:

cd dummy
git rm dummy.2
git commit -m "Get rid of dummy.2"
cd ../split
git rm dummy.1
git commit -m "Get rid of dummy.1"

(download)

So far it looks as if the repositories are split. However, the command git pull in directory "split" will undo the split. Therefore it is also necessary to remove the memory of the clone with

git remote rm origin

(download)


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer