Created
August 23, 2016 09:14
-
-
Save KIVagant/823cf1ab4a5ed127244bb7e784c833aa to your computer and use it in GitHub Desktop.
Copy files from one git repository to another with all history
This file contains hidden or 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
# https://blogs.s-osg.org/retain-history-moving-files-git-repositories/ | |
# http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/ | |
### 1 | |
vim /tmp/git_script.sh | |
#>>>>>> | |
#!/bin/bash | |
mkdir -p newroot/ | |
mkdir -p newroot/src | |
# Pipe output to silence "file not found" warnings. | |
mv old.file newroot/ 2>/dev/null | |
mv src/another.old.file newroot/src/ 2>/dev/null | |
true | |
#<<<<<< | |
### 2 | |
git clone git@oldrepo /tmp/oldrepo | |
cd /tmp/oldrepo | |
git checkout branch_if_needed_or_master | |
git filter-branch -f --prune-empty --tree-filter /tmp/git_script.sh HEAD | |
git filter-branch --prune-empty -f --subdirectory-filter newroot | |
### 3 | |
git clone git@newrepo /tmp/newrepo | |
cd /tmp/newrepo | |
git remote add /tmp/oldrepo | |
git pull old_repo branch_if_needed_or_master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment