Home > Back-end >  git push - "permission denied"
git push - "permission denied"

Time:03-17

I'm new to git and github and I'm trying to push to my repository. I'm currently following github instructions:

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin [email protected]:vlocateli/Programming_principles_and_pratice.git
git push -u origin main

but when I type

git push -u origin main

I get the following error:

error: src refspec main does not match any
error: failed to push some refs to 'https://github.com/vlocateli/Programming_principles_and_pratice.git'

So, I tried the following:

git push origin master

And then I got the following error:

remote: Permission to vlocateli/Programming_principles_and_pratice.git denied to vlocateli.
fatal: unable to access 'https://github.com/vlocateli/Programming_principles_and_pratice.git/': The requested URL returned error: 403

How do I fix this error?

CodePudding user response:

I also faced the same error 2 weeks ago. I uninstalled git from my system and re-installed it. I logged back into my github account and it worked for me. Try doing that.

If that does not work then try the following steps;

  1. Do you have a name of the repo? If yes, instead of using the origin, try passing the repo name

git remote add repo_name url

  1. Again, for the final step

git push repo_name

CodePudding user response:

This is being caused because your remote Git repository does not know about your local repository.

So, you need to set the remote branch as upstream branch of your local branch.

One liner : git push --set-upstream origin master

So, you want your local main to push to remote github main repo.

Detailed

  1. mkdir custom-project
  2. cd custom-project
  3. touch README.md
  4. git init
  5. git remote add origin ssh-version-.git
  6. git add README.md
  7. git commit -m "initial commit"
  8. git push --set-upstream origin master
  • Related