Github often fails to connect and push or pull fails

It is very inconvenient to encounter connection timeouts when using Github daily, resulting in the inability to operate basic push or pull.

It can be used for a short time after "setting the git proxy", and then returns to normal . Frequent connection timeouts greatly affect the development efficiency, so after research and testing, use "SSH" to connect to Github. Everything works fine after testing. It is now recorded as follows:

There are two ways to connect to Github using SSH:

Method 1: Directly use the Git command clone/push/pull

Step 1: Generate public and private keys

Open the "cmd" window and enter: ssh-keygen -t rsa -C "[email protected]"

PS: 1. Save the path by default, just press Enter 2. "passphrase" can be set freely, or it can be empty by default

If the above appears, it means that the key is successfully generated

Key file path:

 As shown above: "id_rsa" represents the private key, and "id_rsa.pub" is the public key (need to be added to Github later)

Step 2: Add the public key "id_rsa.pub" on the Github website

Open the github website, click the avatar in the upper right corner, and select "setting" in the drop-down list:

Select "SSH and GPG keys" in the left menu:

 Click "New SSH key" in the upper right corner, use Notepad to open the public key "id_rsa.pub" file, copy all the content in the file, and copy it to "Key" in "SSH Keys/Add new":

PS: Title can be set freely. In order to distinguish it from the subsequent SSH of "TortoiseGit", it can be set to "Git_SSH" here

After adding the public key on Github, the operation ends. After that, you can directly use commands such as git clone/push/pull in "Git Bash" to connect to the warehouse

Method 2: Use TortoiseGit to connect to Github through SSH

Step 1: Generate a key using TortoiseGit

Find "TortoiseGit - "PuTTYgen" in the start menu of win10

After clicking "Generate", it will start to generate the key, and then add the content shown in "2" in the figure below to Github (the same method as adding the public key in method 1). Then click "Save private key" to save the key generated above (for the convenience of management, you can save it in the same directory in "Method 1")

 Note: The suffix of the key file generated in TortoiseGit is "ppk", which is different from the file suffix of the "rsa" key

Step 2: Add a key for TortoiseGit

1. Find "TortoiseGit -> Pageant" in the Win10 menu

Add the "xxx.ppk" key saved above to the list:

2. After selecting the target project, right-click to select "Setting":

As shown above, add the "Putty key" to the origin warehouse, and select the "xxx.ppk" file saved above.

This completes the setup. After that, you can use the TortoiseGit object to perform operations such as push/pull

Reference link:

Using TortoiseGit, set up ssh to connect to the git warehouse_AresNan's Blog-CSDN Blog

What age is it, and you still can’t connect to GitHub? - Nuggets

Guess you like

Origin blog.csdn.net/m0_47975736/article/details/128538534