SourceTree - theRAPTLab/gsgo GitHub Wiki
This document covers setting up Source tree with Gitlab and Github
When connecting SourceTree with GitLab, you need to use the Add Account section under Preferences.
-
On gitlab.com, create a Personal Access Token and save it in your password manager. You'll find this under your account setting under "Access Tokens". Give it access to API | Read User | Write Repository privileges.
-
In SourceTree Preferences, create an account for GitLab.com. Use your gitlab username and the Personal Access Token you just created. You must then generate a key. Provide a passphrase for the key pair, and save the passphrase in your password manager.
-
Confirm access via SourceTree works by opening the Repository Browser and choosing "remotes". Add the generated
name-Gitlab
keyfile pair to your password manager or whatever. -
On Mac, add the key to the keychain (this is a special option on MacOS to use the built-in keychain):
ssh-add -K ~/.ssh/git-GitLab.
(you may have to chmod 600
the key file before SSH will use it)
- Edit
~/.ssh/config
if necessary (SourceTree should have added it if you let it modify your git config)...in some cases it may mess up and put an incorrect HostName in (GitLab instead of gitlab.com)
EXAMPLE SOURCETREE entry in ~/.ssh/config
# --- Sourcetree Generated ---
Host dasri-GitLab
HostName GitLab
User dasri
PreferredAuthentications publickey
IdentityFile /Users/dsri/.ssh/dasri-GitLab
UseKeychain yes
AddKeysToAgent yes
# ----------------------------
NOTE: This seems to also configure GitLab SSH so you can do git clone
, thanks to the above config.
TROUBLESHOOTING - After setting this up, Fetch and Push seem to fail. Some changes made to the ssh config seem to help:
- change
Host dasri-GitLab
togitlab.com
- comment-out
HostName GitLab
After this, I was able to fetch again from source tree.
Github is more straightforward. When adding a Github account, Sourcetree uses GitHub's oauth setu and authorizes the app. You still need to generate a keypair though, similar to as GitLab does. After the pair is created by SourceTree, it can also modify your ssh config. It adds the following:
# --- Sourcetree Generated ---
Host daveseah-GitHub
HostName github.com
User daveseah
PreferredAuthentications publickey
IdentityFile /Users/dsri/.ssh/daveseah-GitHub
UseKeychain yes
AddKeysToAgent yes
# ----------------------------