Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT Could not read from remote repository

Tags:

git

github

I've cloned a private repo, forked it and made som changes into a feature branch. When I try to push these changes into the repo i get the following message:

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 tried to delete the git credentials from my windows computer controlpanel>credentials but it's still showing me the same error.

Is there any chance that I have to log in and out from my terminal to git? If that would be the case, how do I do that?

I've also tried to push with git push --set-upstream origin but it's just showing me the same error.

Have anyone of you seen this before?

Thanks beforehand, Erik

like image 424
erikos93 Avatar asked Jun 08 '26 07:06

erikos93


2 Answers

"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"

This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:

  1. Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users[YOUR-USER-NAME].ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and id_rsa.pub. These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and id_rsa.pub in order for Git, GitHub, and BitBucket to recognize them by default.
  4. To create the SSH keys, type ssh-keygen -t rsa -C "[email protected]". This will create both id_rsa and id_rsa.pub files.
  5. Now, go and open id_rsa.pub in your favorite text editor (you can do this via Windows Explorer or the OSX Finder if you like, typing open . will open the folder).
  6. Copy the contents--exactly as it appears, with no extra spaces or lines--of id_rsa.pub and paste it into GitHub and/or BitBucket under the Account Settings > SSH Keys. NOTE: I like to give the SSH key a descriptive name, usually with the name of the workstation I'm on along with the date.
  7. Now that you've added your public key to Github and/or BitBucket, try to git push again and see if it works. It should!

More help available from GitHub on creating SSH Keys.

like image 176
Pramod Avatar answered Jun 10 '26 03:06

Pramod


This can be your ssh key is not authorised - Permission denied (publickey).

Solution 1

Check if GitHub protocols are not from ssh to https

check remote url

git remote -v`

Change remote url

git remote set-url origin https://URL

Solution 2

  • Generate a SSH key on your computer
  • Login to your GitHub account
  • Add the newly generated SSH Key to your account through this link
  • Try again to git clone the project.

if after setting ssh key it still fails you might require system restart

Solution 3

This is not a solution just work around for newbies to clone public repo without caring protocols

Use this example

git clone https://github.com/%REPOSITORYFOLDER%/%REPOSITORYNAME%.git

Instead of

git clone [email protected]:%REPOSITORYFOLDER%/%REPOSITORYNAME%.git

all these solutions are collected from different sources will update it if more solution found which works for such scenarios

like image 20
Hanzla Habib Avatar answered Jun 10 '26 04:06

Hanzla Habib



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!