Last active
December 15, 2015 21:29
-
-
Save michal-lipski/5325906 to your computer and use it in GitHub Desktop.
Move Folders Between Git Repositories preserving history using filter-branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create clean clone of the source repository: | |
git clone git://server.com/my-repo1.git | |
Nuke all the entries except the folder you need to move. Use the following command | |
git filter-branch --subdirectory-filter your_dir -- -- all | |
This will nuke all the other entries and their history, creating a clean git repository that contains only data and history from the directory you need. | |
Create a branch for changes. | |
git checkout -b repo1_branch | |
Commit your changes | |
git commit -m "Collected the data I need to move" | |
Now go to your destination repository | |
cd ../my-repo2/ | |
Connect your source repository as a remote using a local reference. | |
git remote add repo1 ../my-repo1/ | |
After that simply fetch the remote source and merge with it | |
git fetch repo1 | |
git merge repo1/repo1_branch | |
Clean up a bit and push the changes to the server | |
git remote rm repo1 | |
git push | |
From: | |
http://www.ifup.org/2009/02/07/the-right-tool-for-the-job-git-stitch-repo/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment