我从我的GitHub帐户克隆了一个Git存储库到我的电脑。
我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。
当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!
我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?
我从我的GitHub帐户克隆了一个Git存储库到我的电脑。
我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。
当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!
我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?
当前回答
如果您在Github帐户上启用了2FA,那么您的常规密码将无法用于此目的,但您可以生成一个个人访问令牌并将其替换为使用。
访问GitHub中的设置->开发人员设置->个人访问令牌页面(https://github.com/settings/tokens/new),并生成具有所有Repo权限的新令牌:
然后页面将显示新的令牌值。保存此值,并在推送到GitHub上的存储库时使用它代替密码:
> git push origin develop
Username for 'https://github.com': <your username>
Password for 'https://<your username>@github.com': <your personal access token>
其他回答
块引用
如果您在请求用户名和密码时遇到$git推送代码问题,请执行以下步骤:
Login to your profile.
Go to settings
click developer settings
->Personal access tokens
--> note: access token
--->Select scopes: checkbox on repo
----> Generate token
-----> Make sure to copy and store it safely if you intend to reuse it.
*** use the generated token as password during pushing code for next 30days ***
***HAPPY CODING***
来源:设置Git
以下命令将在内存中保存密码一段时间(对于Git 1.7.10或更高版本)。
$ git config --global credential.helper cache
# Set git to use the credential memory cache
$ git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after one hour (setting is in seconds)
如果您克隆了HTTPS而不是SSH,并且在pull、push和fetch时遇到用户名和密码提示问题。您可以简单地为UBUNTU解决此问题
步骤1:移动到根目录
cd ~/
创建文件.git凭据
使用用户名密码和githosting URL将此内容添加到该文件
https://user:pass@example.com
然后执行命令
git config --global credential.helper store
现在,您将能够轻松推送并从回购中获取所有详细信息。
你基本上有两个选择。
如果您在两台计算机上使用同一用户,则需要将.pub密钥复制到PC上,这样GitHub就知道您是同一用户。
如果你已经为你的电脑创建了一个新的.pub文件,并希望将这些机器视为不同的用户,你需要在GitHub网站上注册新的.pub文件。
如果这仍然不起作用,可能是因为ssh配置不正确,ssh无法找到密钥的位置。尝试
ssh -vv username@github.com
获取SSH失败的更多信息。
对于那些对前面的答案感到困惑的新手,你可以这样做:
git remote -v
它会做出如下反应
origin https://yourname@github.com/yourname/yourrepo.git (fetch)
origin https://yourname@github.com/yourname/yourrepo.git (push)
然后,您可以运行许多其他人建议的命令,但现在您可以从上面知道您的名字和您的repo,因此您可以将上面的name/yourrepo.git剪切并粘贴到:
git remote set-url origin git@github.com:yourname/yourrepo.git