Solve the problem of `submitting code to github is to enter the username and password`

I have switched github accounts once, and it seems that I have changed the password of the github account once, and then what?
Then every time I submit code to github, I have to enter the username and password (guess is due to the above reasons),
every time , This is too troublesome, so I tried to solve this problem, after a lot of searching, I finally found a solution, share it, and encourage you!!

==============

solution:

Create a new text file in your user directory named .git-credentials
User directory:
windows: C:/Users/username
mac os x: /Users/username
linux: /home/username
Enter in the file created in the previous step The following content:
https:{username} : {password}@github.com
Of course, the above {username} and {password} should be replaced with your github account name and password
. Modify the git configuration and
execute the command git config --global credential.helper store
the above The command will add the following configuration at the end of the ~/.gitconfig file:
[credential]
helper = store
After the above three-step configuration, when you push the code to github, there is no need to enter the username and password~~

=================
Sequel...
Later, I found that the above three steps are not so troublesome, and the simplified process is as follows:

Enter the command at the command line:
git config --global credential.helper store
☞ This step will add at the end of the .gitconfig file in the user directory:
[credential]
helper = store
Now push your code (git push), then it will make You enter the username and password, the username and password entered in this step will be remembered, and you don't need to enter the username and password when you push the code next time!
☞ This step will generate a file .git-credential in the user directory to record the username and password ☞ The
git config --global command actually operates the .gitconfig file in the user directory. Let’s cat this file (cat .gitconfig), and its content is as follows:
[user]
name = alice
email = [email protected]
[push]
default = simple
[credential]
helper = store
git config --global user.email "[email protected] " The operation is the above email
git config --global push.default matching The operation is in the push section above the default field
git config --global credential.helper store operates on the value of the last line above

original information

Author: Yuan Henry Zhen o
Link: https://www.jianshu.com/p/81ae6e77ff47
Source : Jianshu The
copyright belongs to the author. For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325063842&siteId=291194637