'Upload project to different repository

I had a reactjs project which I had already uploaded to a GitHub repository, with git init, git add ., git commit and push.

I deleted this repository and created another one where now I want to make the commits in this new one.

How can I do this?



Solution 1:[1]

If you have deleted the remote one, on GitHub, and created a new empty one (still on GitHub), you can redirect your existing local commits with:

cd /path/to/existing/local/repository
git remote set-url origin https://github.com/MyAccount/MyNewRepo
git push

Solution 2:[2]

You can upload to as many different github/gitlab/bitbucket as you want. Bitbucket being different implementation, slightly different.

This answer focused on github.

inside local repo

git remote add origin ssh-address.

Now the repo can have maximum one "origin" as remote key. For 10 other repository

git remote add origin1 ssh-address1

git remote add origin2 ssh-address2

If you want to replace origin (i.e. the different repo as the main origin)

git remote remove origin

and add remote repo the above way.

Now. for pushing --

git push --set-upstream origin branch-name

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 VonC
Solution 2 Paul Bradbury