3

Via Git UI and Turtoise UI I updated the local and remote GIT repositories. I would like to interact with the gitlab.com repositories in Android Studio and IntelliJ. I keep on getting 401 or read errors.

In IntelliJ I tried to connect to the remote repository via VCS > GIT > Remotes and added the gitlab.com SSH entry. Also in Android Studio I could not connect to the remote repository.

SOLUTION: thanks to VonC. The SSH keys I registered at Gitlab.com were in my c:\users\myusername\.ssh folder. Via the Turtoise and GIT UI I could refer directly to these files.

Both the Android Studio and IJ IDE's use the %HOME% folder to find the SSH keys. This folder may refer tot the System's SSH folder. Because no SSH keys were available in that folder, I kept on getting connection errors.

The solution was in creating a command (.bat) file that does the following for IntelliJ:

set HOME=%USERPROFILE%
c:
cd "C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.3.1\bin"
idea.exe

And for AS:

set HOME=%USERPROFILE%
c:
cd C:\Program Files\Android\Android Studio1\bin
studio64.exe
tm1701
  • 7,307
  • 17
  • 79
  • 168

2 Answers2

1

Let's be clear: if you are using https url, and your username/password GitLab.com account, your ssh keys have nothing to do with your connection attempt: those ssh keys (puttygen or not) will be ignored.

For https, you need your GitLab account credentials, and if your GitLab password has a special character in it, it needs to be percent encoded (like a @).

See also "Handling Passwords for Git Remote Repositories" (again, nothing to do with ssh).

If you select "Clone git repositories using ssh" (as in this answer), then, even if Git does not find your ssh keys (or if your public key is not properly registered in your GitLab account), ssh will be able to fallback to the username/password authentication scheme.


To use ssh urls in AS (Andoird Studio):

  • make sure to launch AS in a CMD session when HOME (type set HOME) is set to %USERPROFILE%,
  • make sure to have generated openssh keys, as described by GitLab and registered to your GitLAb profile, again as described by GitLab.
    You must see in %USERPROFILE%\.ssh (or %HOME%\.ssh) the files id_rsa and id_rsa.pub. No ppk puttygen keys required.

The OP adds:

Ah, the %HOME% and %USERPROFILE% pointed to different locations. I set the id_rsa at %USERPROFILE% and %HOME% points to the system folder. So, using the id_rsa.pub from the C:\WINDOWS\system32\config \systemprofile should also sufficie?

Actually, if HOME points to the system folder, it means AS is running with the system account, or Git was installed for the system account.
Don't: HOME should refers to %USERPROFILE%, and make sure AS is launched with your account. The OP notes:

HOME=%USERPROFILE% solution also works perfectly for IntelliJ, so it is not only for Android Studio.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • For IntelliJ: I created local files, staged and committed them locally. Then via VCS > Git > remote > I added the Https string. Then I pushed the content and it worked fine. QUESTION: where does IntelliJ store the username password for using this Giblab.com private repository? – tm1701 Dec 24 '16 at 17:27
  • For Android Studio: I could clone a project via New > Project from VCS > Git > using the Https gitlab.com string. Worked. What if I have a local repository, how can I store that in the remote repository for the first time? In AS I don't have a 'remotes' option. – tm1701 Dec 24 '16 at 17:31
  • @tjm1706 for your first question, Git for Windows comes with a native integration with the [Windows Credential Store](https://github.com/Microsoft/Git-Credential-Manager-for-Windows) (`git config --global credential.helper manager`) – VonC Dec 24 '16 at 17:34
  • @tjm1706 you always can fallback to the command line, go to your local repo and add a remote that way: `git remote add origin /url/of/remote/repo` – VonC Dec 24 '16 at 17:35
  • AndroidStudio ... I have already aligned the local and remote repo's outside of AS. How can I now start in AS with the remote repo? – tm1701 Dec 24 '16 at 17:44
  • @tjm1706 check if pull/push options are active in AS: that would mean AS recognize your remote repo setting and can pull from or push to it from your local repo. – VonC Dec 24 '16 at 17:46
  • @tjm1706 do you have an error message? In command line, what is the output of `git status` and `git remote -v`? – VonC Dec 24 '16 at 18:12
  • Everything works fine from (separate) Git UI and Turtoise UI. [1] git status = nothing open. [2] $ git remote -v origin4 git@gitlab.com:johan974/GMS.git (fetch) origin4 git@gitlab.com:johan974/GMS.git (push). – tm1701 Dec 24 '16 at 18:51
  • What error message do you have when trying the pull from AS? Does the push work? – VonC Dec 24 '16 at 19:01
  • The error message (screenshot) I have put at the bottom of the issue description. A pull via Turtoise works great. Does this have to do with SSH settings? In Turtoise I have full control of the C:\users\myname\.ssh\* files. – tm1701 Dec 24 '16 at 19:07
  • Yes, ssh could be the issue. An https url should work better. Or at least, try and launch AS from a CMD session where you have set HOME to ℅USERPROFILE℅ first. – VonC Dec 24 '16 at 19:11
  • When I type "set" I see that ℅USERPROFILE℅ points to c:\users\myname. Then I go to the AS bin folder. Type studio64.exe ... same result. When I clone via the http: string of gitlab.com I get a decent clone and can work with it. – tm1701 Dec 24 '16 at 19:25
  • Yes, you net to type `set HOME=℅USERPROFILE℅` first, before launching AS. – VonC Dec 24 '16 at 19:34
  • It was already set. So ℅USERPROFILE℅ pointed to c:\users\myname. That's correct? By the way ... thank you very much for helping. The +50 will be yours unless there is an even better answer. – tm1701 Dec 24 '16 at 19:39
  • Yes, as long as your private public ssh keys are in ℅USERPROFILE℅\.ssh, named id_rsa, and id_rsa.pub, and your public key is registered to your gitlab profile. – VonC Dec 24 '16 at 19:41
  • I have a PUTTYGEN key in the folder as well. It is called id_dsa.ppk and is in the PUTTYGEN format. I checked, no difference. – tm1701 Dec 24 '16 at 19:58
  • No, you need openssh keys, without passphrase, and you need to copy the content of the public key to your gitlab profile – VonC Dec 24 '16 at 20:04
  • @tjm1706 I have included those last comments/recommendations in the answer for more visibility. – VonC Dec 24 '16 at 23:35
  • Thank you very much! Much appreciated! Ah, the %HOME% and %USERPROFILE% pointed to different locations. I set the id_rsa at %USERPROFILE% and %HOME% points to the system folder. So, using the id_rsa.pub from the C:\WINDOWS\system32\config \systemprofile should also sufficie? The answer will help otheres as well, I think. – tm1701 Dec 25 '16 at 08:47
  • Yes, that was the issue! Thanks a lot, I will +50! – tm1701 Dec 25 '16 at 10:34
  • The HOME=%USERPROFILE% solution also works perfectly for IntelliJ. You could update that in your solution, so not only for Android Studio. Thanks again. – tm1701 Dec 26 '16 at 09:32
0

I think you have mistaken GitHub supportwith GitLab projects plugin and trying to authenticate to GitHub using GitLab credentials. Search for GitLab plugin, install gitlab projects: enter image description here

and configure it using GitLab URL and API Key that you can find in your account settings.

enter image description here

agilob
  • 6,082
  • 3
  • 33
  • 49
  • Thanks. For Android Studio, there is no 'gitlab' plugin. For IntelliJ there is only the "gitlab integration" plug-in. Should I use that one? – tm1701 Dec 24 '16 at 15:49
  • @tjm1706 I'm using Android Studio on the screenshots. Click on Plugins -> Browse Repository -> search for GitLab. I added another screenshot. in my answer. – agilob Dec 25 '16 at 10:28
  • Working with the API key ... is that done via the Project > settings > Deploy keys? Which one to use? What is the advantage of using API keys over the SSH keys or username/password? – tm1701 Dec 25 '16 at 12:14
  • API key is used to manage gitlab projects, ssh key to push code changes. – agilob Dec 25 '16 at 16:15
  • Please elaborate. And ... is the API key from gitlab.com found via Project > settings > Deploy keys? – tm1701 Dec 25 '16 at 17:15
  • sshkey is used to security transfer source code between git repositories. api key is gitlab specific to manage your account. – agilob Dec 25 '16 at 17:31
  • That helped. Thank you +1 – tm1701 Dec 25 '16 at 18:31
  • unable to find the api key in gitlab – Sagar Nayak Jan 17 '18 at 03:55