How to Set Up and Push to Two Remote Git Repositories (GitHub and Gitee)
This guide explains how to create identical repositories on GitHub and Gitee, clone them locally, replace the default remote, add both remotes, and push code to each, while also covering common authentication and push‑rejection issues.
This article demonstrates how to manage a project with two remote Git repositories—GitHub and Gitee—so that code can be synchronized to both platforms.
1. Create two remote repositories on GitHub and Gitee, optionally importing one from the other.
2. Clone the repository to your local machine:
git clone [email protected]:Jackson0714/PassJava-Learning.git3. Remove the existing remote named origin :
git remote rm origin4. Add the two remotes with distinct names:
git remote add github [email protected]:Jackson0714/PassJava-Learning.git git remote add gitee [email protected]:jayh2018/PassJava-Learning.gitNote that the remote names are github and gitee , not origin .
5. Verify the configuration using:
$ git remote -vwhich should list both github and gitee for fetch and push.
6. Push to both remotes :
git push github master git push gitee masterYou can also use visual tools such as TortoiseGit to push to all configured repositories.
7. Common issues :
If you see a host authenticity warning, answer yes to continue.
If the push is rejected because the remote has newer commits, either pull the changes first or force‑push with git push gitee master -f .
Following these steps ensures that your local repository stays in sync with both GitHub and Gitee, providing redundancy and broader accessibility.
Wukong Talks Architecture
Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.