Cannot push to my github private repository

Viewed 3222

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 Answers

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?

Related