'Unable to push git local master to remote repository

I'm just trying to push my local master to the remote repository on github, but this is not possible. I have already made a repository in my github directory - on the website, and the app that I'm working on is simple in that I've only been working on the local master - no branches or anything.

When I try 'git push -u origin master' in the terminal, the reply is:

permission denied (publickey)
fatal: could not read from remote repository

When I try 'git push', the response is:

fatal: the current branch master has no upstream branch. To push the 
current branch and set the remote as upstream, use 'git push --set-
upstream origin master'

But when I try 'git push --set-upstream origin master' I get:

Permission denied (publickey).
fatal: Could not read from remote repository.

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

I've been reading as much as I can online on this, but I can't get anywhere, so some advice would be much appreciated, thanks :-)



Solution 1:[1]

You probably do not have permission to read or write from your created repository. You will need to generate a new SSH key and add the public key to your Github account. If you do not know how to do that it is described in detail on https://help.github.com/articles/connecting-to-github-with-ssh/.

Solution 2:[2]

A bit late, but for any one else stumbling upon this, this worked for me.

  1. Open Powershell
  2. Type in "ssh-keygen" (generates your ssh key)
  3. Type in "cat ~/.ssh/id_rsa.pub" (gets your key)
  4. Should look something like this - "ssh-rsa WHOOOOOOLEBUNCHOFTEXT"
  5. Copy it and go to your repo SSH Keys settings (should be in the settings section somewhere. - Gitlab's settings is here https://gitlab.com/-/profile/keys)
  6. Create a new key and paste your ssh key in there.
  7. Ka-bAM - Should be able to push now

Solution 3:[3]

-- If you want to update branch ---

git checkout master

git pull origin master

git checkout YOUR-BRANCH

git rebase master

-- if you want to commit your code ---

git add -A

git commit -m "any comment"

git push origin YOUR-BRANCH

git checkout master

git pull origin master

git checkout YOUR-BRANCH

git rebase master

and finally

git push origin YOUR BRANCH

and after you will submit merge request

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samuel Nilsson
Solution 2 Ruan
Solution 3 Ravi Chauhan