Remote Repository
Conclusion
Corresponding to the local repository is the remote repository. With the remote repository, it is convenient for multiple people to collaborate.
First of all, please register for a GitHub account or a Gitee account (if you don't know what GitHub or Gitee is, please search by yourself).
Generally, you can connect to remote repository through the http protocol, which is convenient and fast and supports anonymous access, but it is recommended to use the more secure ssh protocol, and Git natively supports ssh.
The content of the ssh configuration below is optional. If the http protocol is used, please ignore it.
Use ssh
1.Open Git Bash and execute:
ssh-keygen -t rsa -C "youremail@example.com"
supplement aption
- The key type can be specified with the -t option. If not specified, RSA keys for SSH-2 are generated by default. rsa is used here.
- At the same time, there is a comment field in the key. Use -C to specify the specified comment, which can facilitate the user to identify the key, point out the purpose of the key or other useful information.
- So enter your email address here or whatever.
- After the input is completed, the program also asks for a passphrase, and empty means there is no passphrase.
- Then it will let you enter the password twice, empty means no password.
- Press Enter 3 times to complete the current step.
2.Open your user document C:\Users\yourname\.ssh
, a .ssh
hidden directory will be generated in the user directory, and there are two files in the directory:
id_rsa #private key (unleashed)
id_rsa_pub #public key
3.Log in to GitHub, open the Account settings
, SSH and GPG Keys
page, then, click New SSH Key
, fill in any Title, and paste the content of the id_rsa.pub
file in the Key text box.
Because GitHub needs to recognize that the commits you push are really pushed by you, not someone else's impersonation, and Git supports the SSH protocol, so as long as GitHub knows your public key, it can confirm that only you can push.
Of course, GitHub allows you to add multiple keys. Suppose you have several computers, you submit at the company at one time, and at home at the same time, as long as you add the key of each computer to GitHub, you can push to GitHub on each computer.
If you feel that the ssh connection is troublesome, please ignore the above configuration and use the http connection directly.
Possible problems
If the following occurs when pushing the code:
$ git push -u origin master
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:ntsahdjsab78bdagf3u1TFAN8sbhGAD882bfysabff.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Connection reset by 52.74.223.119 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Solution
Delete the .ssh folder in the user directory, regenerate the ssh key pair according to the above content, deploy it on GitHub, open git bash, execute ssh -T git@github.com
, the result is as follows:
$ ssh -T git@github.com
The authenticity of host 'github.com (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:ntsahdjsab78bdagf3u1TFAN8sbhGAD882bfysabff.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
Hi rumosky! You've successfully authenticated, but GitHub does not provide shell access.