I am trying to move only the contents of one repository (say repo1) to another existing repository (say repo2) using the following commands;
- git clone repo1
- git clone repo2
- cd repo1
- git remote rm origin
- git remote add repo1
- git push
But its not working. I reviewed the other similar post but i only found moving the folder not the contents.
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.
Perfectly described here https://www.smashingmagazine.com/2014/05/moving-git-repository-new-server/
First, we have to fetch all of the remote branches and tags from the existing repository to our local index:
git fetch origin
We can check for any missing branches that we need to create a local copy of:
git branch -a
Let’s use the SSH-cloned URL of our new repository to create a new remote in our existing local repository:
git remote add new-origin git@github.com:manakor/manascope.git
Now we are ready to push all local branches and tags to the new remote named new-origin:
git push --all new-origin
git push --tags new-origin
Let’s make new-origin the default remote:
git remote rm origin
Rename new-origin to just origin, so that it becomes the default remote:
git remote rename new-origin origin
If you're looking to preserve the existing branches and commit history, here's one way that worked for me.
git clone --mirror https://github.com/account/repo.git cloned-repo
cd cloned-repo
git push --mirror {URL of new (empty) repo}
Now, suppose you want to keep the source and destination repos in sync for a period of time. For example, there's still activity within the current remote repo that you want to bring over to the new/replacement repo.
git clone -o old https://github.com/account/repo.git my-repo
cd my-repo
git remote add new {URL of new repo}
To pull down the latest updates (assuming you have no local changes):
git checkout {branch(es) of interest}
git pull old
git push --all new
NB: I have yet to use submodules, so I don't know what additional steps might be required if you have them.
This worked to move my local repo (including history) to my remote github.com repo. After creating the new empty repo at GitHub.com I use the URL in step three below and it works great.
git clone --mirror <url_of_old_repo>
cd <name_of_old_repo>
git remote add new-origin <url_of_new_repo>
git push new-origin --mirror
I found this at: https://gist.github.com/niksumeiko/8972566
It looks like you're close. Assuming that it's not just a typo in your submission, step 3 should be cd repo2
instead of repo1. And step 6 should be git pull
not push. Reworked list:
1. git clone repo1
2. git clone repo2
3. cd repo2
4. git remote rm origin
5. git remote add repo1
6. git pull
7. git remote rm repo1
8. git remote add newremote
There are a lot of complicated answers, here; however, if you are not concerned with branch preservation, all you need to do is reset the remote origin, set the upstream, and push.
This worked to preserve all the commit history for me.
cd <location of local repo.>
git remote set-url origin <url>
git push -u origin master