Created
February 27, 2017 18:17
-
-
Save jonatanblue/5dc8e520944bbf1fc2b7b6f2eab3fbc0 to your computer and use it in GitHub Desktop.
Move a folder from one Git project to another preserving history
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
# Clone repo 1 | |
git clone repo1 | |
cd repo1 | |
# Use subtree on the folder you want to move | |
git subtree split -P dir1 -b split-dir1-branch | |
# Check out branch and move files | |
git checkout split-dir1-branch | |
mkdir dir1 | |
mv * dir1/ | |
git add . | |
git commit -m "Moved all dir1 files back to dir1" | |
# In repo 2, pull down files | |
git clone repo2 | |
cd repo2 | |
git remote add repo1-origin | |
git pull repo1-origin split-dir1-branch | |
# Caveat: git log only shows the last commit | |
# To view the history, use `--follow`: | |
git log --follow dir1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment