Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot push to my github private repository

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?

like image 918
user44697 Avatar asked Nov 18 '17 16:11

user44697


People also ask

Why can I not push to GitHub?

This error mainly occurs when you attempt to push your local changes to GitHub while the local repository (repo) has not yet been updated with any changes made in the remote repo. So Git is trying to tell you to update the local repo with the current changes in the remote before pushing your own changes.

Is there a limit to private repository GitHub?

GitHub has lifted the limit on its private repositories, allowing an unlimited amount of collaborators for all users.


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.
[email protected]:/path/to/repo.git

Only the latter syntax [email protected]: 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 [email protected]: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?

like image 170
VonC Avatar answered Sep 24 '22 14:09

VonC