Skip to content

Instantly share code, notes, and snippets.

@JWhitleyWork
Created June 23, 2019 18:41
Show Gist options
  • Save JWhitleyWork/ab28f8abc1ec4b84baf9ac2abf06cfd4 to your computer and use it in GitHub Desktop.
Save JWhitleyWork/ab28f8abc1ec4b84baf9ac2abf06cfd4 to your computer and use it in GitHub Desktop.
Move Directory Between Git Repos with History
git clone source_repo && cd source_repo
git remote rm origin
git filter-branch -f --tree-filter \
"find -maxdepth 1 -not -name . -not -name .git -not -name folder_to_move -print0 | xargs -0 rm -rf" \
--tag-name-filter cat --prune-empty -- --all
cd ..
git clone target_repo && cd target_repo
git remote add source_repo ../source_repo
git pull source_repo master --allow-unrelated-histories
git push
@JWhitleyWork
Copy link
Author

Replace source_repo, folder_to_move, and target_repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment