Created
June 29, 2020 18:21
-
-
Save titenkov/9a915bbf839b95245b680e3ee356cba8 to your computer and use it in GitHub Desktop.
GIT: Move folder between repositories with `git 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
# Clone the source repository | |
git clone [email protected]:titenkov/api.git | |
# Clean up the git to have only the data and history related to the folder you need | |
git filter-branch -f --subdirectory-filter client/src/integrationtest -- -- all | |
# Move content to some folder matching the desired path in target repository (simpler to merge later) | |
mkdir -p ext/src/integrationtest | |
git mv java ext/src/integrationtest | |
git mv groovy ext/src/integrationtest | |
# Commit your changes, but don't push! | |
git commit -m 'integration tests' | |
# Move to the destination repository | |
# Add a remote repo using the local reference | |
git remote add api ../api/ | |
# Fetch the remote and merge the branch | |
git fetch api | |
git branch api remotes/api/master | |
git merge api --allow-unrelated-histories | |
# Clean up | |
git remote rm api | |
git branch -D api | |
# DONE! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment