【问题标题】:git push access deniedgit push 访问被拒绝
【发布时间】:2019-01-11 23:02:24
【问题描述】:

我认为我在执行 git push 到远程 https 时输入了错误的凭据,因为我不确定要使用哪个凭据。

现在每次我再试一次,我都会收到错误:

远程:HTTP 基本:访问被拒绝致命:身份验证失败 'https://

我应该使用什么凭据以及如何再次尝试?

【问题讨论】:

  • git push -u origin master
  • 由于您正在与 GitHub 交谈,因此您可能要做的一项健全性检查是尝试使用凭据直接登录到 GitHub。如果它们根本不起作用,那么我不会对您当前的观察结果感到惊讶。
  • @slon 我认为这不会解决身份验证错误,并且 OP 没有告诉我们这是他第一次推送。
  • @TimBiegeleisen 如果她是第一次推送,首先会有很多事情要检查,她听起来好像她只是犯了一个错误,并且没有再次收到新的凭据提示。我完全同意您在浏览器上检查凭据以确保错误和正确的建议。
  • @TimBiegeleisen 你是对的。这就是发生的事情。我从浏览器登录 GitHub。我只需要能够从 Git Bash 重试

标签: git github gitlab git-push


【解决方案1】:

谢谢大家的想法,经过尝试,我发现我已经添加了一个来源,所以在删除我的 GitLab 帐户并重新创建它以放置正确的凭据后,我遵循以下步骤:

创建了一个新的远程 git 存储库:

git remote add gitlab https://gitlab.com/myusername/myproject.git

检查我的远程存储库:

git remote -v

我还在远程 gitLab 中创建了一个与本地分支同名的分支:

git pull gitlab mybranch --allow-unrelated-histories
  1. 按“i”
  2. 编写您的合并消息。
  3. 按“esc”
  4. 写“:wq”
  5. 然后按回车键。
git push gitlab mybranch

我希望这可能有用。

【讨论】:

    【解决方案2】:

    如果它是现有项目...在 Git Bash 控制台窗口中导航到项目的根目录。仅键入以下内容以在本地创建存储库。

    git init       (only do this when you first set up repository)
    

    然后

    git add YourFileName
    

    git add *     (to add the whole directory and subdirectories)
    

    然后

    git commit -m "type some comments here within quotes"
    

    (此时登录 github 的网站并仅在您第一次设置存储库时创建存储库 - 在创建存储库后从页面加载中复制并粘贴“git remote add origin master url” . 它看起来像这样:

    git remote add origin https....    (only do this the when you first set up repository)
    

    然后

    git push origin master
    

    从现在开始.. 任何时候您进行需要添加的更改... 只需这样做:

    git add YourFileName
    git commit -m "some comments about the changes made"
    git push origin master
    

    然后,当您登录并查看您的存储库时,您将看到您的更改反映在 Github 的服务器上。

    这是最低限度的...此外,在所有这些都完成并正常工作之前,最好不要使用自述文件或忽略文件进行初始化。

    【讨论】:

    • 非常感谢!这非常有用。我只是有一个问题:我已经有了一个来源,所以我创建了一个新的“git remote add gitlab gitlab.com/username/name.git”,然后我执行“git push gitlab master”,我收到错误“错误:src refspec master 不匹配”任何错误:未能将一些参考推送到“gitlab.com/username/name.git”。我做错了什么?
    • 啊不要做“git push gitlab master”。只需执行“git push origin master”
    【解决方案3】:

    这里是解释如何通过 ssh 将系统连接到 GitHub 的链接

    https://help.github.com/articles/connecting-to-github-with-ssh/

    并成功连接运行

    git push origin master

    【讨论】:

    • 我可以不使用 Git Bash 吗?
    • 你可以。最初当 git 开发时,git 是在/for Linux/Unix 系统中制作的。为了支持在不包含 bash shell 的 windows 中,他们想出了 git Blash。所以所有的命令在 windows、Unix 和 Linux 中都是一样的。
    猜你喜欢
    • 1970-01-01
    • 2016-10-30
    • 2014-06-15
    • 2016-06-02
    • 1970-01-01
    • 2012-05-12
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多