Android Studio - Push failed: fatal: Could not read from remote repository
Asked Answered
H

15

63

I have a git project at Android Studio and a remote at BitBucket and I changed it to use SSH instead of HTTPS. I can make everything work using Atlassian's SourceTree, but in Android Studio every time I try to push the project it says

Push failed: fatal: Could not read from remote repository.

Does anyone have a clue about what could be happening?

Heighten answered 11/7, 2014 at 1:7 Comment(16)
You might have to add the remote again. That error message happens when Git doesn't know where to push to. Check out this similar question: #15410341 I think the top answer should help you.Headachy
But my configurations file has the remote url in it, and SourceTree can make the push...Heighten
and git remote -v shows the remote...using the terminal inside Android StudioHeighten
Hm.. And the remote has the correct SSH url, not the old HTTPS url?Headachy
yes, I changed it myself and I can push via SourceTree....I think this is related to the SSH inside Android Studio, it never asked me where are my keysHeighten
I tried searching for this issue but with "IntelliJ" instead of "Android Studio" to get more results, and I found this: askubuntu.com/questions/436610/… It suggests using a Native SSH executable instead of Built-in so that IntelliJ (or Android Studio, as it were) uses your correct SSH key. This answer implies your concern about Android Studio not asking for your keys is warranted.Headachy
I also find it but it didnt work :/ I am using Win7 x64Heighten
Sorry, those are the only ideas I can think of. I've only used Android Studio on a Mac, so I wouldn't know of any solutions if the issue is specific to Windows. Good luck!Headachy
Thanks a lot anyways....lately my questions are not getting much answers, I appreciate it!Heighten
I wish I could tag people a Google in here....Heighten
Same issue. IdeaU 14 asks to add signature (bitbucket certificate protected) then failures in a big ball of fire.Barbette
Are you using a non-default SSH key? youtrack.jetbrains.com/issue/IDEA-24944 @lokiFictionist
how do I know if I have a non-default SSH key?Heighten
This can be caused by ssh-handshake not working - probably by not presenting the correct key.Grimonia
Have you tested this on yours?Heighten
Tried all these solutions but this one worked for me -> https://mcmap.net/q/79879/-git-remote-repository-not-foundPrimaveria
C
79

This is probably an Intellij problem. Your key are managed natively by ssh, and Intellij has it's own ssh program.

Go to the settings, search git->ssh executable then choose native

As seen here : git with IntelliJ IDEA: Could not read from remote repository

Commandment answered 31/1, 2016 at 8:36 Comment(2)
Thanks for that, this worked on OSx. Normally the default setting works if you are on a clean machine, e.g first time install of Intellij, but in my case the machine has multi-user logins which may have impacted on the defaults.Raseda
This didn't work in my case (for Android Studio 3.1). Please see my answer below.Demy
D
19

Go to Settings > Version Control > Git. Make sure SSH executable is set to “Native.”

If it's already set, switch back to “Built-in,” apply it, and then again switch back to “Native".

enter image description here

Dola answered 25/2, 2018 at 10:7 Comment(3)
This didn't work in my case (for Android Studio 3.1). Please see my answer below.Demy
for those doesn't work, maybe you want to check your current git executable in the terminal: $: which git point the executable and replace it on android In my case, this work on AS 3.2.1 @AlexanderPoleschukExert
@Exert Thanks. After I upgraded to Android Studio 3.2 my problem was fixed.Demy
S
18

There is two ways for Git SSH verification in Android Studio or IntelliJ, changing via: settings - Version Control - Git - SSH excuteable - "Built-in" or "Native"

  1. Built-in : means using ssh key pair built in Git for authentication. you can generate it via
    ssh-keygen -t rsa
    the default saved path is "~/.ssh/id_rsa" and "~/.ssh/id_rsa.pub". You should add the Public key in your BitBucket account. the path like : manage account - SSH keys - add keys
  2. Native : means using the ssh pair generated by the native repository hosting service, such as BitBucket or GitHub, which is often auto-add in the service account. For example in GitHub. It generated a pair of SSH key, "~/.ssh/github_rsa.pub" and "~/.ssh/github_rsa" and the Public key has been auto-added in my account via GitHub GUI maybe. So change the SSH executable to "Native" could be a simple way.

Anyway, you can use the both way after you add the correct Public key in you acoount in repository hosting service.

Siward answered 5/4, 2015 at 16:53 Comment(1)
if you choose built-in: you can refer @kid 's answer. Regenerate your public ssh key and add it to your git hub repository.<br> ssh-keygen -t rsa <br> And the public ssh key is generated in ~/.ssh/id_rsa.pub paste it to you git Hub account. path is <br> account - settings - SSH keysSiward
B
6

Despite my SSH-executable was set to Native I was getting that error because I have set password for SSH key file.

I haven't found the way how to specify password in Android studio but there is another solution, you can remove password which can be done with $ ssh-keygen -p. Then just confirm file location, enter your old password and leave new password blank.

Taken from How do I remove the passphrase for the SSH key without having to create a new key?

Bestiary answered 20/11, 2018 at 22:22 Comment(1)
Followed this but instead of reseting the passphrase, I set it to the same passphrase again. The act of doing this caused Android Studio to eprompt me for the SSH passphrase in a popup when I next pushed... and all was well with the world again.Weinshienk
T
4

Another solution that helped me was "Use credential helper".

Android - Settings

Tachyphylaxis answered 21/1, 2022 at 7:9 Comment(0)
F
2

I got the same issue. Turns out it matters how you run Android Studio. If you run it with normal privileges from terminal or sth, it cannot read local files that it has to in order to push repository.

Solution might just be to restart Android Studio with more privileges than it currently has.

Furrow answered 26/3, 2015 at 23:20 Comment(2)
Are you running it on Windows?Heighten
Surprisingly your solution worked for me. Typical restart trick.Impromptu
B
1

Go to github.com and open your repository and copy USE HTTPS url Go to your Android project directory. In the .git folder search for config file.

IN the config file change url which you copied from github.com (use https) with the previous url. save config file and push again. This worked for me.

Bellbella answered 6/4, 2018 at 6:51 Comment(0)
D
1

I had a similar problem in Android Studio 3.1

I changed Preferences > Version Control > Git > SSH executable from Built-in to Native as suggested here but it didn't help.

Then I upgraded Android Studio to 3.2 and switched back to Built-in. It fixed the issue in my case.

Demy answered 25/10, 2018 at 13:5 Comment(2)
Happy it worked for you. Eventually the switching did the trick, and that is what suggested :)Dola
Maybe but I am not sure :-) I did the switching a few times to Native then back to Built-in. It didn't work until I upgraded to Android Studio 3.2. Thanks anyway.Demy
R
1

Got the issue after switching to Android Studio 3.6 when under the hood it was bumped to IDEA 2019

In my case below solution worked out of the box:

  1. Help - Find Action - Registry...
  2. Find git.use.builtin.ssh and enable it
Raynor answered 28/2, 2020 at 14:22 Comment(0)
O
1

What resolved this issue for me was going into Settings > Version Control > Git and checking "Use credential helper". I had recently downloaded the canary version of Android Studio and opted to not migrate my settings so this little setting which is checked on my release version was no longer checked on the canary version.

Owenism answered 29/6, 2021 at 16:52 Comment(0)
M
0

I ran across this myself, and found the existing answers were a bit incomplete.

tl;dr: Switching Android Studio/IntelliJ's SSH client from built-in to native may resolve the issue for you (it did for me).

Android Studio (effectively a specialized IntelliJ IDEA) comes with its own built-in SSH client, but allows you to switch to native (platform / OS dependent) if you prefer. You can change this by opening your Android Studio options, search for 'git', and choose 'native' in the SSH executable dropdown.

In my case, I was unable to push to BitBucket through Android Studio, but git push worked just fine. Switching to native (OSX SSH, in my case) resolved the issue - now I can push to BitBucket from Android Studio.

Other answers touched on the subject, but there appears to have been some mixup between SSH executables and the keys that they use.

Per Android Studio help under SSH Executable:

  • Built-in: select this option to use the implementation provided by IntelliJ IDEA.
  • Native: select this option to use native implementation.
Maximilianus answered 16/9, 2015 at 1:52 Comment(0)
V
0

I have met this problem, and finally I have solved it. And there are two important points for setting: In the android studio: File-Settings-GitHub: not to choose "Clone git repositories using ssh" In the android studio: File-Settings-Git: Choose "Built-in" for "SSH executable"

and for the SSH that I already have in the account of GitHub, is the one that I have in the android studio, I forget how to find the SSH in the android studio, But you can find it by the other way

Vesuvius answered 17/6, 2017 at 5:10 Comment(0)
U
0

If changing Preferences > Version Control > Git > SSH executable from Built-in to Native is not working then pls try with unchecking the Preferences > Version Control > GitHub>clone git repositories using ssh CHECK IT

Unbeliever answered 6/7, 2019 at 22:0 Comment(0)
C
0

In my case it works at first time but later same error got encountered so i just pushed through terminal

git push -u origin <your branch name>

it will asks for password enter it note i am using bitbucket

Cherilyncherilynn answered 26/3, 2022 at 7:27 Comment(0)
S
-2

Regenerate your public ssh key and add it to your git hub repository.

ssh-keygen -t rsa

It worked in my case.

Seyler answered 12/3, 2015 at 15:38 Comment(1)
I don't know why all the minuses but this actually solved my issueRexrexana

© 2022 - 2024 — McMap. All rights reserved.