It used to store code in github, but it feels good after touching the code cloud. But suddenly found that the upload code was lost, want to upload the results to GitHub on the code cloud, do not know how to switch. After all, git skills are not enough. After online queries, organize them to avoid forgetting them.
Because git itself is a distributed version control system, it can be synchronized to another remote library, of course, it can also be synchronized to two other remote libraries, so a local library can be associated with both GitHub and code cloud!
When using multiple remote libraries, it should be noted that the default name git gives to the remote library is origin. If there are multiple remote libraries, we need to identify different remote libraries with different names. Still take the learngit local library as an example, first delete the associated remote library named origin:
git remote rm origin
Then, first associate GitHub’s remote library:
git remote add github [email protected]:xxx/LearnGit.git
Note that the name of the remote library is github, not origin.
Next, the remote library of the code cloud is associated:
git remote add gitee [email protected]:xxx/LearnGit.git
Also note that the name of the remote library is gitee, not origin.
Now, let’s use
git remote -vLooking at the remote library information, you can see two remote libraries:
gitee [email protected]:xxx/LearnGit.git (fetch) gitee [email protected]:xxx/LearnGit.git (push) github [email protected]:xxx/LearnGit.git (fetch) github [email protected]:xxx/LearnGit.git (push)
If you want to push to GitHub, use the command:
git push github master
If you want to push to the code cloud, use the command:
git push gitee master
In this way, local libraries can synchronize with multiple remote libraries at the same time.