Last active
January 25, 2021 08:59
-
-
Save marcwieland95/606351fffa50dd55e1beb05112992b1c to your computer and use it in GitHub Desktop.
Move folder to new repository and keeping history (inspired by https://gist.github.com/trongthanh/2779392)
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
git clone <repourl>/repo-1.git | |
cd repo-1 | |
git remote rm origin # delete link to original repository to avoid any accidental remote changes | |
git filter-branch --subdirectory-filter dir-to-move -- --all # dir-to-move is being moved to another repo. This command goes through history and files, removing anything that is not in the folder. The content of this folder will be moved to root of the repo as a result. | |
git tag -d $(git tag -l) # remove all tags from the old repository - history should now be clean | |
git remote add master ../new-repo/ # add the link to the new repo | |
git push # the new repo has just the moved folder including the history inside |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment