Move git folder to new repo and retains commit history

If you think a specified folder in your existing repo should be park at other repo then this is a good example to show how to do that and also you never lost any commit history.

Let say I have a repoA with a \folderB which will move into a new repoB

cd \repoA
git filter-branch –-subdirectory-filter folderB -- --all
mkdir folderB
mv * folderB
git add .
git commit

cd ..
git clone repoB.git
cd \repoB
git remote add repoA ..\repoA
git pull repoA master
git remote rm repoA
git push

**caution: You need to create a new repo without any commit yet otherwise you’ll get below error.

fatal: refusing to merge unrelated histories

see http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s