Search code examples
gitlabatlassian-sourcetree

How to add Gitlab-token to sourcetree?


I try to commit a file to a gitlab repo, but I receive

git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks push -v --tags origin main:main remote: You are not allowed to push code to this project. fatal: unable to access 'https://gitlab.server.com/Edna/myproject.git/': The requested URL returned error: 403 Pushing to https://gitlab.server.com/Edna/myproject.git Mit Fehlern abgeschlossen, siehe oben.

Therefore, I got a personal access token from my gitlab operator like:

abcde-aC5unFT3ELQT-VMZKSpV

How do I use this PAT? How to enable this in sourcetree git desktop tool?


Solution

  • Your local repository is configured to use HTTPS instead of git over ssh. The output of git remote -v should verify this. You will see something similar to:

    origin  https://gitlab.server.com/Edna/myproject.git (fetch)
    origin  https://gitlab.server.com/Edna/myproject.git (push)
    

    Follow the instructions to create and add your SSH key to your GitLab account.

    Then, use a SSH remote repository for origin.

    $ git remote rename origin https-origin
    $ git remote add origin [email protected]:Edna/myproject.git
    

    Then, try your git command.