GIT: 当你创建新分支时,遇到“fatal: Could not read from remote repository”的错误。

4
我正在创建新的分支并尝试推送该分支(我已经尝试了以下命令):

git push origin new_branch

git push --all -u
git push origin NewBranch

但是在这两种情况下,我都遇到了这个错误:
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

这是我的 .git/config 文件:
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
[remote "origin"]
        url = ssh://git@github.com/myName/myRepo.git
        fetch = +refs/heads/*:refs/remotes/origin/*
        pushurl = ssh://git@github.com/myName/myRepo.git

这是原始内容:

origin  ssh://git@github.com/myName/myRepo.git (fetch)
origin  ssh://git@github.com/myName/myRepo.git (push)

你们中有人知道这个错误的原因吗?

非常感谢你们的帮助。


在ssh url的//@之间的部分应该是你的用户名。我假设你的用户名可能不是git - Mark Adelsberger
在使用SSH密钥登录GitHub时,用户始终为“git”。看起来您使用的SSH密钥存在问题,无法访问您的存储库。 - zigarn
2个回答

5

仔细检查:

  • your GitHub ssh setting
  • the exact case (upercase/lowercase) of your url myName/myRepo.git
  • if the issue persists with an https url

    git remote set-url origin https://github.com/myName/myRepo.git
    

1

不确定 OP 是否解决了他的问题,但是为了未来的参考(因为这对我自己不久前也有帮助哈哈),问题出在 SSH/OAuth 授权上。我通过替换 OAuth 以进行终端访问并更新我的 gitconfig 文件来解决我的问题:

** OSX Sierra 平台 **

  1. 通过命令 git config -e 检查您的配置文件。
  2. 打开您的钥匙串应用程序。
  3. 搜索 github.com 或 org.github.com(如果您在组织的企业存储库中)。
  4. 选择适当的 github 钥匙串条目 -- 类型为“Internet Password”。
  5. 通过粘贴 OAuth 密钥来编辑密码。
  6. 退出并重试推送到您的存储库,这应该会生成一个要求钥匙串访问权限的弹出窗口。
    • 如果是这样,请允许访问。
    • 如果没有,则您编辑了错误的钥匙串或某些内容没有正确保存。

Git 在 Github 上有很详细的文档,所以如果遇到问题,只需在那里快速搜索一下(或者在 Stackoverflow 上...),希望不会太难解决。人们非常乐于帮助,所以不要害怕问一个愚蠢的问题!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接