Homepage: gozhuyinglong. Making. IO

Gitee:gitee.com/gozhuyinglo…

Github:github.com/gozhuyinglo…

Wechat search: code nong StayUp

I believe that many people who write open source projects will host their code on Github, but with the popularity of code cloud Gitee in recent years, many users also choose code cloud as a remote warehouse. In order to increase visibility for open source projects, code is hosted on both platforms.

So how do you submit your code to both Github and Gitee? This article goes into detail and lists common errors and solutions.

Contents of this article:

1. Use of multiple remote warehouses

Multiple remote repositories are rarely used in projects, but Git itself is supported.

Let’s review Git commands with an example: the example code is already hosted on Github, and now it’s time to add a Gitee remote repository.

1.1 Viewing the Remote Warehouse

Let’s start by looking at the remote repository for the current project

git remote
Copy the code

Otherwise, this should output:

origin
Copy the code

Origin is a name pointing to a remote repository that Git created for you by default when you clone it.

You can view the remote repository address that Origin points to using the following command:

git remote -v
Copy the code

Output result:

origin  https://github.com/gozhuyinglong/blog-demos.git (fetch)
origin  https://github.com/gozhuyinglong/blog-demos.git (push)
Copy the code

This command displays the name and address of the read and write remote repository, in this case Github.

1.2 Renaming the Remote Warehouse

Since the address is Github, let’s change the name to Github for easy identification. Git remote rename

git remote rename origin github
Copy the code

Enter the command to view the remote warehouse and verify whether it is successful. The output is as follows:

github  https://github.com/gozhuyinglong/blog-demos.git (fetch)
github  https://github.com/gozhuyinglong/blog-demos.git (push)
Copy the code

Success!

1.3 Adding another remote repository

Let’s add a remote repository on Gitee by first creating an empty repository on Gitee with the same name as on Github.

Then copy the address at clone/Download.

Git remote add


git remote add gitee https://gitee.com/gozhuyinglong/blog-demos.git
Copy the code

Then check whether it is successful and output the following result:

gitee https://gitee.com/gozhuyinglong/blog-demos.git (fetch) gitee https://gitee.com/gozhuyinglong/blog-demos.git (push)  github https://github.com/gozhuyinglong/blog-demos.git (fetch) github https://github.com/gozhuyinglong/blog-demos.git (push)Copy the code

Success!

1.4 Push/pull of multiple remote warehouses

With multiple remote repositories, push and pull are no longer git push and Git pull as they used to be. You must add the name of the remote repository to identify which remote repository you are operating on. Git push


git pull




git push github main
git pull github main

git push gitee main
git pull gitee main
Copy the code

Git branch –set-upstream — to=

/



git branch --set-upstream-to=gitee/main main
Copy the code

After the association, no branch can be specified

git push github
git pull github

git push gitee
git pull gitee
Copy the code

1.5 Removing a remote repository

To remove a remote repository, use git remote remove

or git remote rm

git remote remove gitee
Copy the code

After you remove a remote repository, all local branches and configuration information of the repository are deleted.

2. Common errors and solutions

It’s certainly not smooth sailing in execution, and if you run into some errors, there may be answers you’re looking for.

2.1 Warning No branch is specified

The following error is reported when pulling:

You asked to pull from the remote 'gitee', but did not specify
a branch. Because this is not the default configured remote
for your current branch, you must specify a branch on the command line.
Copy the code

Git branch –set-upstream =

/



git branch --set-upstream-to=gitee/main main
Copy the code

2.2 No Repository Permission Is Available

When the push operation is performed, the following message will be displayed:

remote: You do not have permission push to this repository
fatal: unable to access 'https://gitee.com/gozhuyinglong/blog-demos.git/': The requested URL returned error: 403
Copy the code

Indicates that you do not have the permission for the remote repository. You need to check whether the remote repository is public, and then check whether the local account and password are correct.

2.3 The remote warehouse is not disclosed

Log in to Gitee and check if the code base is corporate. If not, set it to public.

2.4 Incorrect account and password in Windows Credentials

Open the Control panel and click “User Account”.

Then click “Manage Windows Credentials”

Find your account and change your account and password.

2.5 Delete Windows Credentials and log in again

You can also delete the Windows credentials directly. After the push command is executed, the Windows Security Center login box will be displayed.

Just enter your account number or password.

2.6 Login to the Windows Security Center Cannot be displayed

If the Windows Security center login dialog box cannot be displayed, uninstall it and run the following command:

git credential-manager uninstall
Copy the code

Download and install again from:Github.com/microsoft/G…

2.7 When Github is pushed, a login box is displayed. You can use the SSH address

As shown below, every time you push code, the following login box pops up.

We can change the remote address to an SSH address:

Remove the current Github address and add a new SSH address as described above.

After adding the address, you need to set the SSH Key on Github

2.8 Generate an SSH Key and add it to Github

Type the following command to generate an SSH Key, with your login email address in double quotes

ssh-keygen -t rsa -C "[email protected]" 
Copy the code

If the following prompt is displayed, press Enter. (If it already exists, it will prompt you whether to replace it. Enter Y and press Enter.)

The public key will be generated in your disk directory [C:\Users\ your username.ssh \] to make a memory copy of the file [id_rsa.pub].

Github SSH and GPG keys

Phase to recommend

  • How to Use GitHub to build a Personal Website