我是github上一个组织的所有者,刚刚创建了一个回购并尝试推送,但我遇到了一个问题,它要求我提供我的用户名,尽管我可以SSH很好:

$ ssh -T git@github.com
Hi Celc! You've successfully authenticated, but GitHub does not provide shell access.
$ git add .
$ git commit -m 'first commit'
[master (root-commit) 3f1b963] first commit
 6 files changed, 59 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 main.js
 create mode 100644 package.json
 create mode 100644 readme.markdown
 create mode 100644 views/index.ejs
 create mode 100644 views/layout.ejs
$ git remote add origin https://github.com/WEMP/project-slideshow.git
$ git push -u origin master
Username for 'https://github.com':

我做错了什么?这从来没有发生在我身上,但我最近也升级到git 1.7.10.3。


当前回答

附加说明:

如果你已经添加了一个远程($git remote add origin…)并且需要更改特定的远程,然后首先执行远程删除($ git remote rm origin),然后重新添加新的和改进的回购URL(其中“origin”是远程回购的名称)。

我们用原来的例子:

$ git remote add origin https://github.com/WEMP/project-slideshow.git
$ git remote rm origin
$ git remote add origin https://github-username@github.com/WEMP/project-slideshow.git

其他回答

我刚刚收到一封来自github.com管理员的电子邮件,内容如下:“我们通常建议人们使用HTTPS URL,除非他们有特定的理由使用SSH协议。HTTPS更安全,更容易设置,所以我们在创建新的存储库时默认使用HTTPS。”

密码提示确实接受正常的github.com登录详细信息。关于如何设置密码缓存的教程可以在这里找到。我遵循了教程中的步骤,它对我很有效。

以下是官方给出的答案:

If Git prompts you for a username and password every time you try to interact with GitHub, you're probably using the HTTPS clone URL for your repository. Using an HTTPS remote URL has some advantages: it's easier to set up than SSH, and usually works through strict firewalls and proxies. However, it also prompts you to enter your GitHub credentials every time you pull or push a repository. You can configure Git to store your password for you. If you'd like to set that up, read all about setting up password caching.

因为你使用的是HTTPS方式。HTTPS要求您每次尝试推或拉时都输入您的帐户访问权限,但也有一种方法,称为SSH,它让您告诉git,我给了您这台pc的帐户权限,并且永远不会再问我任何用户访问权限。要使用它,您必须生成SSH密钥,并将其添加到您的Github帐户,只需一次。要做到这一点,您可以遵循以下步骤

如何为Github生成SSH密钥

附加说明:

如果你已经添加了一个远程($git remote add origin…)并且需要更改特定的远程,然后首先执行远程删除($ git remote rm origin),然后重新添加新的和改进的回购URL(其中“origin”是远程回购的名称)。

我们用原来的例子:

$ git remote add origin https://github.com/WEMP/project-slideshow.git
$ git remote rm origin
$ git remote add origin https://github-username@github.com/WEMP/project-slideshow.git

根据@Ianl的回答,

如果启用了两步身份验证,则必须使用令牌而不是密码。 你可以在这里生成一个令牌。

如果你想禁用用户名和密码的提示,那么你可以设置URL如下-

git remote set-url origin https://username:password@github.com/WEMP/project-slideshow.git

注意,URL同时具有用户名和密码。此外,.git/config文件应该显示您的当前设置。


更新20200128:

如果您不想在配置文件中存储密码,那么您可以生成您的个人令牌并用令牌替换密码。这里有一些细节。

它看起来是这样的

git remote set-url origin https://username:token@github.com/WEMP/project-slideshow.git