gitmergerepositorymigrate

Moving Git repository content to another repository preserving history


I am trying to move only the contents of one repository (repo1) to another existing repository (repo2) using the following commands:

git clone repo1
git clone repo2
cd repo1
git remote rm origin
git remote add repo1
git push

But it's not working. I reviewed a similar post, but I only found one moving the folder, not the contents.


Solution

  • I think the commands you are looking for are:

    cd repo2
    git checkout master
    git remote add r1remote **url-of-repo1**
    git fetch r1remote
    git merge r1remote/master --allow-unrelated-histories
    git remote rm r1remote
    

    After that repo2/master will contain everything from repo2/master and repo1/master, and will also have the history of both of them.