我从我的GitHub帐户克隆了一个Git存储库到我的电脑。

我想使用我的电脑和笔记本电脑,但只有一个GitHub帐户。

当我尝试使用我的电脑推送到GitHub或从GitHub中拉取时,它需要用户名和密码,但当我使用笔记本电脑时不需要!

我不想每次与origin交互时都键入用户名和密码。我在这里缺少什么?


当前回答

如果您克隆了HTTPS而不是SSH,并且在pull、push和fetch时遇到用户名和密码提示问题。您可以简单地为UBUNTU解决此问题

步骤1:移动到根目录

cd ~/

创建文件.git凭据

使用用户名密码和githosting URL将此内容添加到该文件

https://user:pass@example.com

然后执行命令

git config --global credential.helper store

现在,您将能够轻松推送并从回购中获取所有详细信息。

其他回答

一个常见的原因是使用默认(HTTPS)而不是SSH进行克隆。您可以通过转到存储库,单击“克隆或下载”,然后单击URL字段上方的“使用SSH”按钮,然后更新源远程的URL,如下所示:

git remote set-url origin git@github.com:username/repo.git

您可以使用以下方法检查是否已将远程添加为HTTPS或SSH:

git remote -v

GitHub中记录了这一点:将远程URL从HTTPS切换到SSH。

如果您在Windows下使用Git(例如,GitBash)(如果您不想从HTTPS切换到SSH),也可以使用Windows的Git凭据管理器

此应用程序将为您保留用户名和密码。。。

如果SSH密钥或.netrc文件不适用于您,那么另一个简单但不太安全的解决方案可能适用于您:git credential store-Helper将凭据存储在磁盘上:

git config --global credential.helper store

默认情况下,凭据将保存在文件~/.git凭据中。它将被创建并写入。

请注意,使用此助手将在磁盘上存储未加密的密码,仅受文件系统权限的保护。如果这可能不是可接受的安全权衡。

块引用

如果您在请求用户名和密码时遇到$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)