Skip to content

Instantly share code, notes, and snippets.

@KIVagant
Created August 23, 2016 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KIVagant/823cf1ab4a5ed127244bb7e784c833aa to your computer and use it in GitHub Desktop.
Save KIVagant/823cf1ab4a5ed127244bb7e784c833aa to your computer and use it in GitHub Desktop.
Copy files from one git repository to another with all history
# 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