当从网上克隆一个仓库时,有两种URL可以选择,一种是HTTPS URLs(任何场景下都可以工作,推荐方式),另一种是SSH URLs。
通常我们选择的是使用HTTPS URL来clone仓库
当使用HTTPS方式克隆仓库时,对仓库的一些更改操作,比如说git push,需要用户输入username and password。这是因为Github采取了two-factor authentication,双重验证方式来保证安全。(每次验证的时候,需要输入用户名和密码),或者如果要授权某个组织,给第三方软件,来访问Github,则需要提供personal access token。
如果不想每次输入用户名和密码,则可以使用credential.helper(凭证助手)来记住Username和Password。
$ git config credential.helper store
$ git push https://github.com/owner/repo.git
# 然后输入用户名和密码
Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>
这样下次再git push时,就不用输入用户和密码了。
还可以设置记住时间:
git config --global credential.helper 'cache --timeout 7200' # 这里设置账号信息被记住7200秒,两个小时。
原文:https://blog.csdn.net/tsq292978891/article/details/89316612
网友评论