为什么Github在按照屏幕上的说明并推送新的回购时要求输入用户名/密码?

Kit*_*nde 274 git github

我是github上的一个组织的所有者,只是创建了一个repo并尝试推送但是我遇到了一个问题,即使我可以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':
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?这在我之前从未发生过,但我最近也升级到git 1.7.10.3.

Hug*_*ugo 625

不要使用HTTP而是使用SSH

更改

https://github.com/WEMP/project-slideshow.git 
Run Code Online (Sandbox Code Playgroud)

git@github.com:WEMP/project-slideshow.git
Run Code Online (Sandbox Code Playgroud)

你可以在.git/config文件中做到这一点

  • 您也可以执行`git remote set-url origin git@github.com:user/repo.git`,详见/sf/ask/708846701/ - 用于回购的凭据/ 10126412#10126412 (8认同)
  • 您可以通过单击复制克隆URL的按钮来更改此选项. (2认同)

Sea*_*ean 51

我有同样的问题,并想知道为什么用一个用https克隆的bitbucket repo没有发生.稍微调查一下,我发现BB repo的配置有一个包含我的用户名的URL.所以我手动编辑了GH repo的配置,就像这样,瞧,没有更多的用户名提示.我在Windows上.

编辑your_repo_dir/.git/config(记住:.git文件夹被隐藏)

更改:

https://github.com/WEMP/project-slideshow.git
Run Code Online (Sandbox Code Playgroud)

至:

https://*username*@github.com/WEMP/project-slideshow.git
Run Code Online (Sandbox Code Playgroud)

保存文件.做一个git pull测试它.

执行此操作的正确方法可能是使用git bash命令编辑设置,但直接编辑文件似乎不是问题.


Cat*_*tcu 20

这是对此的正式答案:

如果Git每次尝试与GitHub交互时都会提示您输入用户名和密码,那么您可能正在使用存储库的HTTPS克隆URL.

使用HTTPS远程URL有一些优点:它比SSH更容易设置,并且通常通过严格的防火墙和代理工作.但是,每次提取或推送存储库时,它还会提示您输入GitHub凭据.

您可以配置Git为您存储密码.如果您想设置它,请阅读有关设置密码缓存的所有信息.


kau*_*hal 12

改进@ Ianl的答案,

如果要禁用用户名和密码的提示,则可以按如下方式设置URL -

git remote set-url origin https://username:password@github.com/WEMP/project-slideshow.git
Run Code Online (Sandbox Code Playgroud)

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


小智 10

附加说明:

如果您已经添加了一个远程($ git远程添加源...)并且需要更改该特定远程,那么在重新添加新的和改进的repo URL之前,先进行远程删除($ git remote rm origin) "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
Run Code Online (Sandbox Code Playgroud)

  • 您不必删除遥控器.您只需更改URL:`git remote set-url origin https:// github-username @ github.com/WEMP/project-slideshow.git` (4认同)

a p*_*erd 7

如果您使用的是HTTPS,请检查以确保您的URL正确。例如:

$ git clone https://github.com/wellle/targets.git
Cloning into 'targets'...
Username for 'https://github.com': ^C

$ git clone https://github.com/wellle/targets.vim.git
Cloning into 'targets.vim'...
remote: Counting objects: 2182, done.
remote: Total 2182 (delta 0), reused 0 (delta 0), pack-reused 2182
Receiving objects: 100% (2182/2182), 595.77 KiB | 0 bytes/s, done.
Resolving deltas: 100% (1044/1044), done.
Run Code Online (Sandbox Code Playgroud)

  • 这是一个很好的观点!如果 URL 中有拼写错误,系统将提示您输入“用户名”,而不是告知存储库不存在。 (3认同)

joc*_*hen 6

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

密码提示确实接受了正常的github.com登录详细信息.有关如何设置密码缓存的教程,请访问https://help.github.com/articles/set-up-git#password-caching.我按照教程中的步骤操作,它对我有用.


Haz*_*yan 5

因为您使用的是HTTPS方式。HTTPS要求您在每次尝试推送或拉取时都输入您的帐户访问权限,但也有一种方法,称为SSH,它可以让您告诉 git,我已授予您使用我的帐户使用这台电脑的权限,并且从不询问我再次关于任何用户访问。要使用它,您必须生成 SSH密钥并将其添加到您的 Github 帐户中一次。为此,您可以按照以下步骤操作

如何为 Github 生成 SSH 密钥


Nei*_*eil 5

如果您启用了双因素身份验证,则需要生成个人访问令牌并使用它而不是常规密码。更多信息在这里:https : //help.github.com/articles/creating-an-access-token-for-command-line-use/