【问题标题】:How to "git push" to private repository with prompt for username and password?如何在提示输入用户名和密码的情况下“git push”到私有存储库?
【发布时间】:2015-11-18 05:29:19
【问题描述】:

我已经将我的 private Github 存储库克隆到我的 CentOS 6 机器上(git 版本 1.7.1)。我可以以某种方式将我的本地 git 存储库设置为在输入 git push 时始终提示输入用户名和密码吗?

不会总是使用相同的用户名。

$ cat .git/config 

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://github.com/USER/PRIVATE-REPO.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

当我现在执行git push 时,我得到了这个:

error: The requested URL returned error: 403 Forbidden while accessing https://github.com/Industriromantik/render-linux.git/info/refs
fatal: HTTP request failed

如果我执行以下,则推送成功:

git push https://MY-GITHUB-USERNAME@github.com/USER/PRIVATE-REPO

...但是,如果可能的话,我只想执行git push 并提示 用户名和密码。

【问题讨论】:

  • 私人意味着它只是一个您从自己的机器托管的 git 存储库?
  • 您的私人仓库的设置中是否列出了任何贡献者?
  • 不,我的意思是我在通过 github 网站创建存储库时选择了“私有”。
  • 不,我的存储库设置中没有贡献者。
  • 尝试添加贡献者,看看在尝试推送时是否会打开提示。

标签: git github


【解决方案1】:

使用https://克隆存储库

$ git clone https://github.com/user/private-repo.git/

因为(似乎)https 连接不缓存密码(也不缓存用户名,除非你在 URL 中提供),git 总是会要求你输入密码(和用户名):

$ git push
Username for 'https://github.com': USER
Password for 'https://USER@github.com': ****
$

【讨论】:

  • 你的建议给了我一个错误:Initialized empty Git repository in /home/fredrik/repo/.git/ error: The requested URL returned error: 403 Forbidden while accessing https://github.com/user/repo.git/info/refs fatal: HTTP request failed
  • 执行git --version会得到什么?
  • 这是git version 2.6.2
【解决方案2】:

【讨论】:

  • 我希望完全与您的建议相反。我不想缓存用户名。我希望命令git push总是询问用户名和密码。
  • 抱歉我的误解 git config credential.helper 'cache --timeout=1' 或者你可以删除你的凭据,通常人们会问如何存储凭据!
  • git config --global --unset credential.helper
  • 我克隆了我的私有存储库并尝试了git config --global --unset credential.helper,但这只会提示我输入密码,而不是用户名。我错过了什么吗?
  • 能否请您打印一下.gitconfig
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-23
  • 2022-01-12
  • 2018-07-18
  • 2018-03-06
  • 2015-04-24
  • 1970-01-01
相关资源
最近更新 更多