我已经使用Git有一段时间了,但是不停地要求输入密码让我感到非常烦恼。
我使用的是Mac OS X和GitHub,按照GitHub的 Set Up Git页面 的指示设置了Git和我的SSH密钥。
我还像GitHub的SSH key passphrases页面上提到的那样,将github SSH 密钥添加到了我的Mac OS X密钥链中。我的公钥已在Git中注册。
尽管如此,每次我尝试Git pull时,都需要输入我的用户名和密码。除了SSH密钥之外,还需要设置其他内容吗?
我已经使用Git有一段时间了,但是不停地要求输入密码让我感到非常烦恼。
我使用的是Mac OS X和GitHub,按照GitHub的 Set Up Git页面 的指示设置了Git和我的SSH密钥。
我还像GitHub的SSH key passphrases页面上提到的那样,将github SSH 密钥添加到了我的Mac OS X密钥链中。我的公钥已在Git中注册。
尽管如此,每次我尝试Git pull时,都需要输入我的用户名和密码。除了SSH密钥之外,还需要设置其他内容吗?
我同意"codehugger"的观点,并使用"orkoden"的指示为我解决了问题,在NetBeans 7.3中,当你右键单击文件并选择上下文菜单——推送——一个“推送到远程”窗口会打开——这里有两个选项:
origin:https://github.com/myaccount/myproject.git/
https://github.com/myaccount/myproject.git/
正如你所看到的,URL中的原点参数是不同的。你不想选择选项(1),你只需要检查选项(2),这对我来说完全没问题。
git remote remove origin
git remote add origin git@github.com:PrestaShop/PrestaShop.git
xpetta@host:~/home/xpetta$ git push
fatal: The current branch ABC-123 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin ABC-123
或者您可以打开.git/config
文件,找到[remote "origin"]
部分,并确保正在使用的URL不以https
开头。如果以https
开头,请将其替换为远程GitHub存储库中的ssh
URL。同样适用于.git/config
中列出的其他服务,如fetch等,需要替换为ssh
URL。
根据您的配置,有不同类型的身份验证。以下是其中一些:
git credential-osxkeychain
.
If your credential is invalid, remove it by:
git credential-osxkeychain erase
or:
printf "protocol=https\nhost=github.com\n" | git credential-osxkeychain erase
So Git won't ask you for the keychain permission again. Then configure it again.
See: Updating credentials from the OS X Keychain at GitHub
Your SSH RSA key.
For this, you need to compare your SSH key with what you've added, check by ssh-add -L
/ssh-add -l
if you're using the right identity.
Your HTTPS authentication (if you're using https
instead of ssh
protocol).
Use ~/.netrc
(%HOME%/_netrc
on Windows), to provide your credentials, e.g.
machine stash1.mycompany.com
login myusername
password mypassword
了解更多:在 Stack Overflow 中 与 GitHub 同步。
~/.gitconfig
中,以强制git在所有GitHub存储库中使用SSH而不是HTTPS:[url "ssh://git@github.com/"]
insteadOf = git://github.com/
insteadOf = https://github.com/
如果您主要使用公共仓库,也可以使用pushInsteadOf
而不是insteadOf
,因为从公共仓库读取可以在无需身份验证的情况下完成。
git fetch http://username@gerrit-domainname/repositoryname refs/changes/1/12345/1 && git cherry-pick FETCH_HEAD
这个URL在另一台机器上挑选时效果很好。然而,在我的机器上,当我尝试使用正确的密码abc@12345
进行挑选时,我会收到以下错误:
remote: Unauthorized
remote: Authentication failed for http://username@gerrit-domainname
url = ssh://gerrit-domainname:8080/wnc
解决方案:
我通过提供在我的Gerrit账户-设置-HTTP密码中找到的HTTP密码来解决身份验证失败的问题。
HTTP密码类似于Th+IsAduMMy+PaSS+WordT+RY+Your+OwNPaSs
,与我的实际密码abc@12345
完全不同。
注意:我的cherrpick URL以git fetch ...
开头。因此,此解决方案可能适用于URL以git fetch ...
开头的git checkout/download。
遇到了相同的问题。
请确保您已正确设置远程源:
$git remote add origin master "https://...git "
choco install gh
然后运行以下命令:
gh auth login
请遵循指示
您也可以点击此链接:
步骤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
第二步:移除您的远程源
git remote rm origin
git remote add origin https://your_git_username:your_git_password@github.com/path_to_your_git.git
git branch --set-upstream master origin/master
- bownie
netrc
”。在这里查看完整示例。 - VonC