How can I provide permission to myself to push to github from the command line?

2.2k Views Asked by At

I am trying for the first time to use git and GitHub to version control my project.

Here is what i have done

  1. I added a new SSH Key to my machine using the docs "Generating a new SSH key and adding it to the ssh-agent"
  2. I created a project on GitHub without readme.md file as recommended.
  3. Using the command line, I changed directory to my project. Then, I executed the commands listed below

However, the git push command is giving me the following error

remote: Permission to VENDORNAME/PROJECT-NAME.git denied to malhayek2014. fatal: unable to access 'https://github.com/VENDORNAME/PROJECT-NAME.git/': The requested URL returned error: 403

Here are the commands I ecexuted before running into the errors

echo "A message for the read me file" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/VENDOR-NAME/PROJECT-NAME.git
git push -u origin master

How can I communicate with Github and push code to it?

2

There are 2 best solutions below

3
On BEST ANSWER

When you want to use SSH for pushing and pulling you have to use the ssh URL (which looks like [email protected]:username/project.git) and not the https URL.

In order to update an existing repository you can issue the following command:

git remote set-url origin [email protected]:VENDOR-NAME/PROJECT-NAME.git

See https://help.github.com/articles/changing-a-remote-s-url/

PS: The error message you provide indicates that you are successfully authenticated using https, however, you don't have persissions to push to that repository - that's independent to the SSH problem. You need to add yourself to the team if you are one of the owners or ask the owners to do so - or add your SSH key as a deployment key.

1
On

you can install github cli then everything will work