GIT:任何设置默认登录凭据的方法?

时间:2011-10-20 21:50:32

标签: git

我正在使用终端为mac并运行该行

git push origin master

每次都要求我输入我的github.com用户名和密码,
有没有办法让它自动使用我的凭证?


我一直收到错误

error: The requested URL returned error: 403 while accessing 
https://github.com/atheycreek/churchdeploy.git/info/refs

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://github.com/atheycreek/churchdeploy.git

所以我把它改成了

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git:github.com/atheycreek/churchdeploy.git

现在我得到..

kirkstrobeck:churchdeploy kirkstrobeck$ git push origin master
ssh: Could not resolve hostname git: nodename nor servname provided, or not known
fatal: The remote end hung up unexpectedly

我把它改成了

[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = git@github.com/atheycreek/churchdeploy.git

现在我得到..

kirkstrobeck:churchdeploy kirkstrobeck$ git push origin master
fatal: 'git@github.com/atheycreek/churchdeploy.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

5 个答案:

答案 0 :(得分:16)

根据您对事物的描述,听起来您的[Project Dir] / .git / config文件设置为行url = https...,而不是url = git@github.com...。你能检查一下这个文件,看看它的内容吗?如果您可以发布整个“远程起源”部分,那就太棒了。它可能看起来像这样:

[remote "origin"]
    url = https://github.com/atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*

但需要使用ssh而不是http:

[remote "origin"]
    url = git@github.com:atheycreek/churchdeploy.git
    fetch = +refs/heads/*:refs/remotes/origin/*

答案 1 :(得分:10)

使用空密码正确设置您的ssh密钥,您无需输入凭据:http://help.github.com/mac-set-up-git/

答案 2 :(得分:5)

如果在OSX上,您应该能够使用osxkeychain助手。您可以通过键入以下内容来检查是否已安装它:

git credential-osxkeychain

如果您收到一条消息,指出这不是有效的git命令,您可以通过以下方式安装它:

curl -s -O http://github-media-downloads.s3.amazonaws.com/osx/git-credential-osxkeychain
chmod u+x git-credential-osxkeychain
sudo mv git-credential-osxkeychain `dirname \`which git\``

然后告诉git使用它:

git config --global credential.helper osxkeychain

下次执行拉/推时,系统会要求您再次提供凭据。从那时起,git应该记住你的信息。

答案 3 :(得分:1)

使用空密码被认为是不好的做法。引用Help.Github

  

密码不是很安全,你已经知道了。如果你使用一个   这很容易记住,更容易猜测或蛮力。如果你   使用一个随机的,很难记住,因此你更多   倾向于写下密码。这两个都非常糟糕   事情™。这就是你使用ssh密钥的原因。

     

但是使用没有密码的密钥基本上与写入相同   将随机密码放在计算机上的文件中。任何获益的人   访问您的驱动器已访问您使用的每个系统   关键。这也是非常糟糕的事情。解决方案很明显:添加   密码短语。

这里正确的解决方案是使用ssh-agent - 这样,Git每次会话只会要求您输入一次密码。有关如何在系统上进行设置的说明,请参阅this page

答案 4 :(得分:0)

设置您的API令牌以及您的SSH凭证(密码较少,但最好使用代理密码)

其他答案中的link provided也提供了相关说明。具体来看底部的第2步。

相关问题