Unable to authenticate Gitlab in Sourcetree

Sourcetree Gitlab Auth Blocker

In Sourcetree, when I select “GitLab.com” (private token auth type is selected by default), I enter my Gitlab username and password (SSH, id_rsa.pub). I cannot change the id_rsa.pub to the recommended ED25519 option.

Even though the correct user name and password are entered, I get the following error:
“Login error, We couldn’t connect to GitLab with your (username) credentials. Check your username and try the password again.”

I’ve tried connecting via Gitlab CE and also through HTTPS. Nothing seems to work though I can git commit via Terminal.

Has anyone else encountered this auth issue with GitLab? I was formerly on GitHub and didn’t have any issues with auth. I did enable 2FA if this causes problems with Sourcetree?

Hi @grehce, welcome to the GitLab Community forum! :tada:

I’ve seen other GitLab users have this problem before and believe I know what the solution is.

When “Private Token” is selected for “Auth Type” for connecting GitLab to Sourcetree, you actually need to enter a Personal Access Token in the “Password” field, not your regular password. Sorry for any confusion.

To generate a private token, navigate to https://gitlab.com/profile/personal_access_tokens, create an personal access token with scope of api, read user, and write repository, and use this in place of your password when connecting your account to Sourcetree.

For GitLab CE the steps to set up Sourcetree to use private token will be almost identical, the only difference being the URL to create the token to use in place of your password will use a different URL: <your_gitlab_url>/profile/personal_access_tokens

Please let us know if this resolves the problem for you, and don’t hesitate to ask if you have any questions.

1 Like

Thanks @gitlab-greg. The token worked for adding the account but I’m now blocked on push/pulls. I get thrown this auth prompt and neither the token or GitLab password work:

HI @grehce it looks like the request here is for the password associated with your ssh key, not an access token or account password. I can tell this is the case because its requesting password for user git, not your username, and the error message in screenshot 2 is: git@gitlab.com: Permission denied (publickey).

Did you set a password when creating the SSH key affiliated with your GitLab account? If so, can you try entering that password in the prompt in your first screenshot?

Let us know how it goes!

Thanks @gitlab-greg. Weirdly, the Password prompt pops up twice when I enter the password associated with the SSH key which led me to initially believe that my password was incorrect because the prompt was thrown twice; however, if I enter the same password again, the pull successfully completes.

Is there a way to set the password so that I don’t have this password requirement on every push/pull?

Hi @grehce, glad you were able to get in!

To avoid having to frequently enter your SSH key password, you can add it to your ssh key “keychain”.

Here’s how to do this on MacOS:

1 Like

Thank you so much for getting me onboarded, @gitlab-greg!

1 Like

I’m happy to hear that worked for you, and glad I could help! :tada: :partying_face:

1 Like

I’ve done all of this, even managed to get my GitLab remote repos to display in SourceTree in on the remote tab… but when I try to clone one of my repos, then it errors: abort: repository <repo_name> not found

Hi, I would like to recommend to all guys this link and it works for me
https://www.awordfromnet.com/access-gitlab-via-sourcetree-updated/

As I know, this resolved my issue when I put my PAT as password and username for login. But it seems to not working because it is missing api scope.

It’s probably late, but hope it helps you.

PROBLEM SOLVED

The solution was (on Mac):

  • revoke the old Access Token from GitLab (which had only the next Scopes: read_repository, write_repository)

  • generate new Access Token having the next Scopes: api, read_user , read_repository, write_repository (it was strange that for other colleague it worked only with read_repository, write_repository)

  • on SourceTree: go to SourceTree → Preferences ->Accounts → Add → fill-in the details as in the following image (and for Password use the Access Token)

after this, I was able to Clone Repository (“Clone from URL”)

also, this link inspired me: https://www.awordfromnet.com/access-gitlab-via-sourcetree-updated/

1 Like