我使用Git已经有一段时间了,但不断的密码请求开始让我感到很烦。

我使用的是Mac OS X和GitHub,我按照GitHub的设置Git页面的指示设置Git和SSH密钥。

我还将github SSH密钥添加到了我的Mac OS X密钥链中,正如github的SSH密钥密码页面中提到的那样。我的公钥已在Git中注册。

然而,每次我尝试Git拉时,我都必须输入用户名和密码。除了SSH密钥之外,我是否需要为此设置其他东西?


当前回答

我觉得static_rtti提供的答案在某种意义上很粗糙。我不知道这是否在早期可用,但Git工具现在提供了凭据存储。

缓存模式

$ git config --global credential.helper cache

使用“缓存”模式将凭据保存在内存中一段时间。没有一个密码存储在磁盘上,15分钟后将从缓存中清除。

存储模式

$ git config --global credential.helper 'store --file ~/.my-credentials'

使用“存储”模式将凭据保存到磁盘上的纯文本文件中,它们永远不会过期。

我个人使用的是商店模式。我删除了存储库,克隆了它,然后必须输入一次凭据。

参考:7.14 Git工具-凭证存储

其他回答

Microsoft Stack解决方案(Windows和Azure DevOps)

首先打开.git/config文件,确保地址如下:

protocol://something@url

例如,Azure DevOps的.git/config:

[remote "origin"]
    url = https://mystore@dev.azure.com/mystore/myproject/
    fetch = +refs/heads/*:refs/remotes/origin/*

如果问题仍然存在,请打开Windows凭据管理器,单击名为Windows凭据的安全框并删除所有与git相关的凭据。

下次登录git时,它不会再消失。

步骤1:检查当前配置

cat .git/config

您将获得:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = https://github.com/path_to_your_git.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[user]
    name = your_username
    email = your_email
[branch "master-staging"]
    remote = origin
    merge = refs/heads/master-staging

步骤2:删除远程源

git remote rm origin

步骤3:使用用户名和密码添加远程源

git remote add origin https://your_git_username:your_git_password@github.com/path_to_your_git.git

我有这个问题。回购要求我每次都输入凭证。我所有的其他经纪人都没有要求我出示证件。他们甚至被设置为在相同的帐户凭据下使用HTTPS跟踪GitLab,所以奇怪的是,除了一个,他们都工作得很好。

比较.git/config文件,我发现导致问题的URL中有两个关键差异:

确实要求提供凭据:

https://gitlab.com/myaccount/myproject

不要求提供凭据:

https://myaccount@gitlab.com/myaccount/myproject.git 

因此,添加“myaccount@”和“.git”解决了我的问题。

我同意“codehugger”,并使用“orkoden”的指令,它对我有效-在NetBeans 7.3上-当您右键单击文件并选择上下文菜单-push-打开“push to remote”窗口时-这里有两个选项:

来源:https://github.com/myaccount/myproject.git/https://github.com/myaccount/myproject.git/

正如您所看到的,区别在于URL中的原始参数-您不想选择此选项(1),您想检查选项(2),这对我来说很好。

面临着同样的问题。

请确保已正确设置远程原点:

$git remote add origin master "https://...git "