Skip to content

Instantly share code, notes, and snippets.

@Macrofig
Last active July 6, 2016 17:58
Show Gist options
  • Save Macrofig/8281d989d245777ccd1d8d5bf93ab3b2 to your computer and use it in GitHub Desktop.
Save Macrofig/8281d989d245777ccd1d8d5bf93ab3b2 to your computer and use it in GitHub Desktop.
Commands to copy component from one repo to another along with git history
# Credit to this article for the following commands:
# http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
# Prepare the source repo
mkdir ~/move-commits/source
git clone <git-url> ~/move-commits/source
cd ~/move-commits/source
git checkout master
git pull origin master
git remote rm origin
git filter-branch --subdirectory-filter <target-folder> -- --all
mkdir -p <target-folder>
mv * <target-folder>
git add .
git commit -m 'Staged code for copying to new repo'
# Prepare the target repo
git clone <git-url> ~/move-commits/target
cd ~/move-commits/target
git checkout -b feature/copy-code-from-source-repo
git remote add soure-repo ~/move-commits/source
git pull soure-repo master
git remote rm soure-repo
git push origin feature/copy-code-from-source-repo
# Clean up
rm -rf ~/move-commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment