I have followed these instructions below to upload a project.
Global setup:
Download and install Git
git config --global user.name \"Your Name\"
A quick way to fix this if you're using a Mac is to sign out of the OSX app and log back in.
Adding public key is the solution.For generating ssh keys: https://help.github.com/articles/generating-ssh-keys has step by step instructions.
However, the problem can persist if key is not generated in the correct way. I found this to be a useful link too: https://help.github.com/articles/error-permission-denied-publickey
In my case the problem was that I was generating the ssh-key without using sudo but when using git commands I needed to use sudo. This comment in the above link "If you generate SSH keys without sudo, then when you try to use a command like sudo git push, you won't be using the SSH key you generated." helped me.
So, the solution was that I had to use sudo with both key generating commands and git commands. Or for others, when they don't need sudo anywhere, do not use it in any of the two steps. (key generating and git commands).
I tried the solutions mentioned but still failed. I found the solution that finally worked for me here - removing then re-adding the remote link
Type the following command using your username and repository name:
git clone https://github.com/{user name}/{repo name}
in Ubuntu this works perfectly.
You need to set up SSH keys.
This GitHub page explains how to generate keys.
If you have an existing key, you copy $HOME/.ssh/id_rsa.pub
and paste it into the GitHub SSH settings page.
I had to add my public key to github. https://help.github.com/articles/generating-ssh-keys