Gangmax Blog

Split Git sub directory to a new repository

From here and here.

For the “such-cat” project, the commands are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
cd ~/temp/github/copper-controller-qe
git subtree split -P tools/NiQI/Tools/such-cat -b such-cat-only
cd ~/temp/github/
mkdir such-cat
cd such-cat
git init
git pull ../copper-controller-qe such-cat-only
# Recover to a previous version.
git reset --hard 4a0f2c4b64b8146ed13ed583528660e3bc0100fd
# 1. If it's the first time to do so, do the following.
# Now a local Git repo for such-cat is created. Create the remote
# such-cat repo on Github, then executing the following commands.
git remote add origin https://github.com/username/such-cat.git
git push origin -u master
# 2. If it's not the first time to do so, which means a repo is
# already existing in Github, do the following commands.
git branch --set-upstream-to=origin/master master
git pull
# Fix possible conflicts and then:
git commit -a -m 'Add the latest code changes from Stash.'
git push origin master
# Done.

For the “such-clowder” project, the commands are:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
cd ~/temp/github/copper-controller-qe
git subtree split -P tools/NiQI/Tools/such-clowder -b such-clowder-only
cd ~/temp/github/
mkdir such-clowder
cd such-clowder
git init
git pull ../copper-controller-qe such-clowder-only
# Recover to a previous version.
git reset --hard 8d9a4013d562396913be5a09ac008bbc705ccef2
# Now a local Git repo for such-clowder is created. Create the remote
# such-clowder repo on Github, then executing the following commands.
git remote add origin https://github.com/username/such-clowder.git
git push origin -u master
# Done.

Comments