Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve remote SSH push github error

I have created SSH key linked to github. I am trying to remotely push a file to the created repository

these are my code

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/demo_repo2.git
git push -u origin main

But it is giving me error as :

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.

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

I have checked whether ssh key is linked , and it is. It is even giving

git remote -v

origin  [email protected]:user/repo2.git (fetch)
origin  [email protected]:user/repo2.git (push)

I tried almost all answers , but not working . Please someone help me

like image 921
Kosmo Avatar asked May 09 '26 17:05

Kosmo


1 Answers

It should not give you this error, since you have set an HTTPS URL with:

git remote add origin https://github.com/username/demo_repo2.git

Check git config -l for any url."[email protected]:".insteadOf https://github.com/ directive.

If git remote -v does give you an SSH URL, that means the first git remote add origin must have failed.
You can force an HTTPS URL with:

cd /path/to/my/repo
git remote set-url  origin https://github.com/username/demo_repo2.git
like image 80
VonC Avatar answered May 11 '26 16:05

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!