Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't git push to Bitbucket: Unauthorized - fatal: Could not read from remote repository

Tags:

git

bitbucket

I can't push to Bitbucket and this is the error message:

> git push origin master:master
Unauthorized
fatal: Could not read from remote repository.

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

Debugging, I receive this message when I ssh to bitbucket:

> ssh -T bitbucket.org
authenticated via a deploy key.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

This deploy key has read access to the following repositories:
my-username/my-repository

The read access part of this message is suspicious.

PS: I know there are dozens of similar questions, but I couldn't find the exact error message here and only got the solution outside. That's why I'm self answering this to help others.

like image 737
Zanon Avatar asked Jun 30 '19 23:06

Zanon


People also ask

How do you fix fatal could not read from remote repository please make sure you have the correct access rights and the repository exists?

The Git “fatal: Could not read from remote repository” error occurs when there is an issue authenticating with a Git repository. This is common if you have incorrectly set up SSH authentication. To solve this error, make sure your SSH key is in your keychain and you connecting to a repository using the correct URL.

Does not appear to be a Git repository could not read from remote repository?

Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.

Does not appear to be a Git repo?

The “… does not a appear to be a git repository” error is triggered when you try to clone, or run other commands, in a directory that is not recognized as a Git repository. The directory or remote file path might not have initialized Git, or the file path you are trying to access as an active repository is incorrect.


1 Answers

I was able to solve this using this suggestion:

  1. Remove the SSH key from the repo. (Click on repo name > Settings > Access Keys)
  2. Add SSH key to Account settings SSH keys. (Click on your avatar > Personal Settings > SSH Keys)

So, adding the keys under the repo only gives you a read-only access. For read and write access, you need to add your keys under your account.

To be fair, Bitbucket warns about the read-only access when adding the key to the repo: image showing the bitbucket message warning about the read-only access

like image 91
Zanon Avatar answered Sep 19 '22 04:09

Zanon