Cannot push to my github private repository

两盒软妹~` 提交于 2020-12-30 09:37:07

问题


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

I can successfully connect to my GitHub account:

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

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

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?


回答1:


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

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

Then try and push again.


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

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

Only the latter syntax user@host.xz: uses the ssh config file.

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

See "History of the SSH protocol".

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

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?



来源:https://stackoverflow.com/questions/47368660/cannot-push-to-my-github-private-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!