Solution:
每次都需要输入用户名和密码是因为你采用的是 https 方式提交代码, 如果采用的是 ssh 方式只需要在版本库中添加用户的 sha 的key就可以实现提交时无需输入用户名和密码。
Detailed steps: Step 1:
If your repository is already created with HTTPS, you will need to delete the original submission method first. Execute the following command at the terminal:
add origin [email protected].com:(用户名)/版本库名
Here I provide my specific example:
https:https://github.com/User name/gittest.git
SSH: [email protected]: User name/gittest.git
How do I know that? If you choose not to create a readme.md when you create the repository, you are prompted to create:
HTTPS:...or Create a NewRepositoryOn the command LineEcho# gittest >> readme.mdGit initgitAddReadme.mdgit commit-m"First Commit"Git remoteAddOriginHTTPS://github.com/sugerming/gittest.gitgit push-u Origin Master ...orPush anExisting repository from the command LineGit remoteAddOriginHTTPS://github.com/sugerming/gittest.gitgit push-u Origin masterssh: ...or Create a NewRepositoryOn the command LineEcho# gittest >> readme.mdGit initgitAddReadme.mdgit commit-m"First Commit"Git remoteAddOrigin [email Protected]:sugerming/gittest.gitgit push-u Origin Master ...orPush anExisting repository from the command LineGit remoteAddOrigin [email Protected]:sugerming/gittest.gitgit push-u Origin Master
Step 2:
Then this time you use the following command to submit the code:
push -u origin master
The system prompts you to:
The authenticity ofHost ' github.com (192.30. 252. 131) ' Can ' t be established. RSA Key Fingerprint isSHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.Are sure you want to ContinueConnecting (yes/no)? Yeswarning:permanently added ' github.com,192.30. 252. 131' (RSA) to the List ofKnown H osts. Permission denied (publickey). fatal:could not Read fromRemote Repository. Sure make theCorrect access rights
Indicate that you have insufficient authority. So you need to create your own RSA key locally. As follows:
ssh-keygen-t-C"用户名"
Then the system will ask you to save the path and so on, I skip the direct enter.
Generating public/privatefileintothe key (/c/Users/AlexYi/.ssh/id_rsa):Enter passphrase (emptyfor no passphrase):Enter same passphrase again:
Then the system will generate something:
inpublickeyinkeyiskey‘s randomart image is:2048]----+| .o.+. || o o.|| . o|| o |...
The main thing is to tell you that you can be in:
publickeyin /c/Users/AlexYi/.ssh/id_rsa.pub
Locate the file, and then open it with Notepad to see your key:
ssh-rsa AAAAB3NzaC1yc2EAAAADA...
Step 3:
Then add the generated RSA key to the Repository, by:
Open your own repository and click Settings on the right to enter the configuration page.
Then click on the left navigation bar: Deploy keys to enter the Add Key page
Then click on: Add deploy keys to enter your own content in it.
So it's done.
Finally continue to commit the changed code, using:
push -u origin master
can be submitted successfully.
Add:
If you want to use a git push
short commit code:
push
Configuration Required:
git config --global push.default simple
Or:
git config --global push.defaultmatching
The difference is that the former only submits the branch you are currently in, and the latter commits the local or left branch. Just check it out for yourself.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Git push needs to enter a username and password every time