Example commands show moving the "data" directory from oldrepo to newrepo and includes all history.
-
Clone a fresh copy of oldrepo.
git clone [email protected]:USERHERE/oldrepo.git cd oldrepo
-
Switch to the branch you want the code/data from.
git checkout main
-
Optional: git-filter-repo if you want to prune history to match certain dirs/files.
# Example (multiple "--path file" or "--path dir" args may be passed, space separated) git filter-repo --path data
-
Clone a fresh copy of newrepo.
git clone [email protected]:USERHERE/newrepo.git cd newrepo
-
Checkout the branch on newrepo that you want to merge oldrepo into.
git checkout develop
-
Add a new remote that tracks the local oldrepo.
git remote add local-oldrepo ../oldrepo/
-
Fetch branches from the local oldrepo 'remote':
git fetch local-oldrepo
-
Create a new temporary branch on newrepo that tracks the local 'remotes/local-oldrepo/branch' as an upstream.
git branch develop-tmp remotes/local-oldrepo/main
-
Merge the newly created temporary branch into the currently checked out branch on newrepo. (In this example, develop is still checked out on newrepo.)
git merge develop-tmp --allow-unrelated-histories
- You may have to deal with merge conflicts for commonly named files.
-
Push your branch to the upstream git server (once satisfied with the results)
git push --set-upstream origin develop
Remove newrepo's remote reference to the local oldrepo and the temporary branch that tracked it.
git remote rm local-oldrepo
git branch -d develop-tmp
Remove oldrepo's local copy.
rm -rf oldrepo