Git: Move files from one repo to another with history (2021)
a year ago
- #RepositoryManagement
- #Git
- #VersionControl
- Exporting files with history between Git repos can be complex, but using `git filter-repo` simplifies the process.
- `git filter-branch` is no longer recommended due to history rewriting issues and warnings from Git CLI.
- Patching is an alternative but can be complex and less seamless compared to `filter-repo`.
- Install `git filter-repo` separately, as it's not included with Git CLI by default.
- Key `filter-repo` options: `--path` to include files/folders, `--invert-paths` to exclude them.
- Steps to move files with history: clean source repo, add source as remote in target repo, fetch and merge changes, then cleanup.
- Perform cleanup in a local branch first to avoid impacting the original repo.
- Use `git remote add`, `git fetch`, and `git merge --allow-unrelated-histories` to integrate changes.
- Cleanup involves removing the remote source and branch after merging.