Skip to content

Instantly share code, notes, and snippets.

@titenkov
Created June 29, 2020 18:21
Show Gist options
  • Save titenkov/9a915bbf839b95245b680e3ee356cba8 to your computer and use it in GitHub Desktop.
Save titenkov/9a915bbf839b95245b680e3ee356cba8 to your computer and use it in GitHub Desktop.
GIT: Move folder between repositories with `git filter-branch`
# Clone the source repository
git clone git@github.com: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