====== Move files to another git repo and preserve history ====== git filter-branch is a mess, use python3 git-filter-repo instead to filter the commits to be saved to the new repo. Steps used: 1) Create a new local branch of the source repo (A) and switch to it (branchOnRepoA). 2) Filter the directories that you want to keep from A using git-filter-repo. This will rewrite history. It should de downloaded first from https://github.com/newren/git-filter-repo python3 git-filter-repo --force --path src/main/resources/folder1 --path src/main/resources/folder2 3) In destination repo (B) we should add A as a remote source repo git remote add source C:\repoA source - remote repo name C:\repoA - path to the remote source repo 4) From B import data from A: git fetch source 5) From B, merge A branch: git merge source/branchOnRepoA --allow-unrelated-histories 6) From B, remove A: git remote remove source 7) From B, push changes: git push "origin" main:main If git repo is hosted in gitlab and you receive the error: "You can only push commits if the committer email is one of your own verified emails.", check repo settings in gitlab and uncheck the following checkbox: {{:git:pasted:20231124-123408.png}} 8) Clean-up local branch created in step 1).