Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to access gitlab via sourcetree

Srivatsan Madhavan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 10, 2023

Hi all,

I have tried using the personal token access method and SSH key method but unable to connect gitlab via sourctree. It keeps throwing an error saying 'Authentication Failed'. I am not sure how to proceed with this. Any help will be appreciated. 

 

Picture1.png

 

I created a personal access token and copied the password to a local file. Pasted the password when prompted through 'Refresh PAT' and this throws an error 'Authentication failed'. I am not sure what the root cause for the problem is. Any help will be greatly appreciated thanks.  

1 answer

0 votes
LynnG
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
August 1, 2026

This is usually a credential-format or token-scope issue rather than a Sourcetree-only problem. For GitLab over HTTPS, GitLab says you can authenticate using a personal access token as the password, and if 2FA or SAML is enabled you must use a PAT instead of your normal password. [docs.gitlab.com]

Things to check first

1. Use your GitLab username, not email

In Sourcetree, use:

Plain Text
1
Username: your GitLab username
2
Password: your GitLab personal access token
3
Protocol: HTTPS
Show more lines

Do not use your GitLab account password as the password field. Atlassian Community answers for Sourcetree/GitLab also point out that the PAT should be used as the password when adding the GitLab account. [community....assian.com], [community....assian.com]

2. Create a fresh token with the right scopes

For clone/pull/push over HTTPS, GitLab documents these relevant scopes:

Plain Text
1
read_repository allows repository pull/read access
2
write_repository allows repository read/write access, including push
3
api grants complete read/write API access for the token scope
Show more lines

[docs.gitlab.com]

For Sourcetree account integration, many users report success with:

Plain Text
1
api
2
read_user
3
read_repository
4
write_repository
Show more lines

Atlassian Community and Stack Overflow examples specifically mention api and read_user, and some users resolved the issue by adding repository scopes too. [community....assian.com], [stackoverflow.com]

3. Do not use “Refresh PAT” with your GitLab password

When Sourcetree prompts during Refresh Personal Access Token, enter:

Plain Text
1
Username: GitLab username
2
Password: newly generated PAT
Show more lines

not your GitLab password. This is a common point of confusion in Sourcetree’s UI. [community....assian.com]

Clear cached bad credentials

If you previously entered the wrong password/token, Sourcetree or Git may keep reusing it.

On Windows:

  1. Open Credential Manager
  2. Go to Windows Credentials
  3. Remove entries related to:
    • gitlab.com
    • your GitLab Enterprise URL
    • SourceTree
    • git:https://...

Then reopen Sourcetree and try again with the fresh PAT.

Verify outside Sourcetree

Before troubleshooting Sourcetree further, test the same credentials with Git directly:

Shell
Show more lines

When prompted:

Plain Text
1
Username: your GitLab username
2
Password: your PAT
3
 
Show more lines

If this fails too, the problem is likely the token, scopes, username, repository permission, or GitLab URL.

If you prefer SSH

For SSH, make sure:

  1. The public key is added in GitLab under SSH Keys.
  2. Sourcetree is using the matching private key.
  3. Your remote URL is SSH, not HTTPS:
Shell
1
git@gitlab.com:group/project.git
Show more lines

If the remote still starts with https://, SSH keys will not be used.

Most likely fix

Create a new PAT with:

Plain Text
1
api
2
read_user
3
read_repository
4
write_repository
Show more lines

Then remove cached GitLab credentials from Windows Credential Manager and add the GitLab account again in Sourcetree using your GitLab username and the PAT as the password.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events