无法推送到我的github私有存储库 [英] Cannot push to my github private repository

查看:232
本文介绍了无法推送到我的github私有存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习git时,我已经在 GitHub 上建立了一个私有存储库.我已经创建了ssh密钥并将其存储到我的GitHub帐户中,并在本地Linux机器上编辑了.ssh/config文件:

As I'm learning git, I have set up a private repository on GitHub. I have created ssh key and store it to my GitHub account and edited .ssh/config file on my local Linux machine:

    ## github
        Host github.com
        User git
        HostName github.com
        IdentityFile ~/.ssh/github.key

我可以成功连接到我的GitHub帐户:

I can successfully connect to my GitHub account:

    $ ssh -T github
    Hi <UserName>! You've successfully authenticated, but GitHub does not provide shell access.

我已经在本地计算机上初始化了一个git存储库,设置了用户并添加了一个远程存储库:

I have initialized a git repository on my local machine, set up user and added a remote repository:

    $ git init
    $ git config user.name "UserName"
    $ git config user.email "UserEmail"
    $ git remote add origin ssh://github:<UserName?/<repositoryName>.git

我创建了一个 README.md 文件,并将其添加到git中并提交:

I have created a README.md file, added it to git and commited it:

    $ git add README.md
    $ git commit -m "First commit."

现在,每次我尝试推动时,都会出现此错误:

Now everytime I try to push, I get this error:

    $ git push origin master

    ERROR: Repository not found.
    fatal: Could not read from remote repository.

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

克隆存储库是可行的,但这是我唯一能做的事情.

Cloning the repository works, however that is the only thing I can do.

为什么我不能推送到我的私有存储库?我在做什么错了?

Why can't I push to my private repository? What am I doing wrong?

推荐答案

请改用 scp语法,以确保使用您的〜/.ssh/config 文件:

Try instead the scp syntax, to make sure your ~/.ssh/config file is used:

git remote set-url origin github:<username>/<repo>

然后尝试再次推动.

Git本身使用OpenSSH版本(至少一个带有 Windows版Git的软件包)

Git itself uses an OpenSSH version (at least the one packages with Git for Windows)

> ssh -V
OpenSSH_7.5p1, OpenSSL 1.0.2k  26 Jan 2017

如"为什么ssh命令不遵循URI上的RFC?中所述,之间的区别:

As explained in "Why doesn't the ssh command follow RFC on URI?", there is a difference between:

ssh://[user@]host.xz[:port]/path/to/repo.git
vs.
user@host.xz:/path/to/repo.git

仅后一种语法 user@host.xz:使用 ssh配置文件.

最初开发SSH时,它是作为更安全的直接替代早期RSH/rlogin工具套件的开发.

When SSH was originally developed, it was developed as a more secure, drop-in replacement for the earlier RSH/rlogin suite of tools.

请参阅" SSH协议的历史".

OpenSSH (1999)早于(2005年1月发布)

OpenSSH (1999) predates URI (finalized in RFC 3986, published in January 2005)

如果允许主机部分以 host:port 的形式出现,则会产生潜在的歧义: jdoe@host.example.com:2222 是否引用了连接到标准端口上的〜host.example.com 上的〜jdoe/2222 时,还是根本没有引用任何文件(或更糟糕的是,〜jdoe通过端口2222连接时在 host.example.com 上的)?

If the host portion was allowed to be on the form host:port, this would create a potential ambiguity: does jdoe@host.example.com:2222 refer to ~jdoe/2222 on host.example.com when connecting on the standard port, or does it refer to no file at all (or worse, ~jdoe) on host.example.com when connecting over port 2222?

这篇关于无法推送到我的github私有存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆