One of the most popular places to store and share your code online is GitLab. And one of the best free desktop Version control tools is without any doubt Sourcetree. Here is a quick overview of how to link them without losing any precious time and energy.
So here is my setup:
- A GitLab account.
- A Macbook machine (setup in Windows is similar).
- A local installation of Sourcetree – version 4.0.2 (236), with embedded Git, version 2.27.0
- On your browser, open your GitLab account.
- Go to User Settings > Access Tokens.
- Create a new Token, using Add a personal access token, granting the access you want Sourcetree to have from Scopes
- Click on Create personal access token button to complete the setup.
- Copy the Token value.
- Back on Sourcetree, go to Preferences > Accounts
- Click on Add… button to add your GitLab account.
- Now this is the most tricky (and confusing part). On Username, enter your GitLab username. On Password, instead of entering your GitLab password, you need to enter the Personal Access Token that you just created.
- Change the Protocol to HTTPS.
- Click Save.
You can now use your newly setup account to clone locally the GitLab repository you need.
Further reading – clone a GitLab repository:
- In Sourcetree, go to Window > Show Repository Browser
- Click on New… > Clone from URL
- Enter the Source URL of the repository you want to clone (something like https: //…./somerepo.git)
- Destination path is the folder on your machine, where you’d like to keep the local version of the repo
- Name is a unique name that you give to the local repository
Before you can push any changes to your GitLab repositories, you need to create a SSH key in Sourcetree and paste it into GitLab. Here are the steps to do it.
- When cloning a new GitLab repo, you will have the initial option to specify a SSH key. It is then saved then into a .PUB file on your machine. What you need to do once this is created is to copy the file content and use it in GitLab.
- With the text, copied into your Clipboard, open your browser, then your GitLab account.
- Go to User Settings > SSH Keys.
- Paste the text into the Key input field.
- Give the key some Title, such as Sourcetree SSH key.
- Optionally, set a Expire at date for this token.
- Click on Add Key button.
You can now clone, pull and commit into your GitLab repositories, using Sourcetree.
One thought on “Link Sourcetree to your GitLab account”
Cheers! Much appreciated.