How do I login to Sourcetree?
Asked by Mike Schellenberger:

I can find no way to login to my account from Sourcetree. I can see and use repositories in our Bitbucket just fine. I've just added a new personal repo in Bitbucket and attempting to add it as a remote via Windows with current version of Sourcetree.

On the remote tab I see my account with a red X. Interesting that I can work with company repos but this seems to imply I'm not logged in. I look around and can find no way to login to Sourcetree.

What does the red X mean? How do I login to see my remotes repos in Bitbucket?


Answers:
author: minnsey
body: Hi  

Sourcetree effectively deals with 2 types of credentials, git/hg ones and REST ones, although they contain the same information.  

Ignoring Sourcetree for a second if you know the remote HTTPS URL to a private Bitbucket repository and try to clone it via the git command line, git will prompt you for a username/password. If these credentials are valid it will store them in the Windows Credential Manager, prefixed with 'git:'  

When Sourcetree acts on a repository it asks git to do all the work and git will retrieve any suitable credentials from the Windows Credential Manager, so Sourcetree effectively can pull/fetch/push etc without prompting for additional credentials.  

In the Sourcetree Tools/Options/Authentication tab it is possible add a Sourcetree account for Bitbucket. This has the effect of re-defining the 'git:' credentials in the Windows Credential Manager, but also sets 'hg:' credentials for use with Mercurial and 'sourcetree' credentials for use when calling REST APIs.

from the sound of it, your 'git:' credentials are correct, you can interacts with your Bitbucket repository via git, but the REST ones are out of sync, hence the red X in the remotes tab.   

To correct this open Tools/Options/Authentication tab and edit the Bitbucket account there and refresh the credentials, you should get confirmation that they are now 'good' and you should then be able to see remote repositories listed in Sourcetree and interact via Git

comments: author: Mike Schellenberger
body: Sorry....I didn't reply in the correct box and it won't let me paste my reply here and submit it nor can I delete my reply as an answer.


author: Mike Schellenberger
body: Hi Michael,

From your description it would seem that if my BitBucket credentials were no good I should not be able to interact with any repo in BitBucket from within Sourcetree. I was able to interact with my existing company repo just fine from within Sourcetree. What I have never been able to do is to submit a Pull request from within Sourcetree, I've had to manually do this via the website. I would get directed to BitBucket with an error message saying thats no good here. The initial part of the url looked correct for our account.

Anyway, I followed your directions on editing my account and refreshed the credentials. Now I can see listed in remotes ONLY my new personal repo, my company repo does not show up.

Why do I only see the new personal repo under remotes? I have a feeling this is also related to me not being able to do a Pull request from Sourcetree.

comments: author: Mike Schellenberger
body: Hi Michael,

From your description it would seem that if my BitBucket credentials were no good I should not be able to interact with any repo in BitBucket from within Sourcetree. I was able to interact with my existing company repo just fine from within Sourcetree. What I have never been able to do is to submit a Pull request from within Sourcetree, I've had to manually do this via the website. I would get directed to BitBucket with an error message saying thats no good here. The initial part of the url looked correct for our account.

Anyway, I followed your directions on editing my account and refreshed the credentials. Now I can see listed in remotes ONLY my new personal repo, my company repo does not show up.

Why do I only see the new personal repo under remotes? I have a feeling this is also related to me not being able to do a Pull request from Sourcetree.


author: minnsey
body: So the missing company entries from the listing **might** be a bug. Can you explain how you are related to those repositories, e.g. by permissions, group membership, individual invite etc?  

What error do you get for the pull-request? Do you get as far as the Bitbucket website?


author: Mike Schellenberger
body: After my reply above I was able for the first time to create a Pull request from Sourcetree. I had submitted a bug for this with details sometime back. I just went back to Sourcetree to view remotes and I am again showing up with Red X by my account and see no remotes. I do the many odd steps to refresh and only see my personal repo listed again.

I don't remember how I was added to BitBucket. Originally I was added as an admin or some high level but being new to Git and BitBucket (I'm a long time MS guy) I asked some rights be taken away. Earlier this morningbefore posting this question I spent a half hour trying to find how I see my rights/permissions in BitBucket but gave up.

So why did I need to refresh a token again from a couple of hours ago. This just seems wrong as the steps required to refresh are horrible so I wouldn't expect this is normal.


author: minnsey
body: So Bitbucket;s OAuth acces tokens expire after an hour, but Sourcetree and the Git Credential Manager (GCM) v 1.14 or higher, shipped with Git for Windows, has the ability to auto-refresh the access tokens using a refresh token.  

Older versions of GCM/Git do not have that ability and will cause the access token and then the refresh token to be invalidated.  

It sounds like that is what is happening to you.  

I d experience this occasionally when using things like Visual Studio and/or Code which also talk to Git because I have multiple versions of Git installed for testing and something will run an old Git and invalidate my tokens. Occupational hazard of developing a Git client.  

Any chance you have multiple copies of Git installed?


author: Mike Schellenberger
body: I'm not running multiple versions that I can tell. I see only one Git folder with one set of commands in the Start menu and in 'Program Files' and nothing under 'Program Files x86'.

I have v2.16.1(4), thats a Feb 2018 release and I did not update it. I will guess a recent Visual Studio update 'automagically' did that without my knowledge.


author: Mike Schellenberger
body: Today I get a new error when creating a Pull request. After pushing a change with

git push --set-upstream origin AuthMvcUpdate

When I go to the remotes, right click the new branch AuthMvcUpdate and choose 'Cretae Pull request...' I get the following error.

You don't have any remotes which have extended integration settings configured; you need to edit your remotes to add details such as the hosting type and base URL. Click the Settings button to open your remote list.

I only have 1 remote and am currently connected to it.


author: minnsey
body: You need to open the repository settings, the cog in the upper left and then select and Edit the remote and ensure the Optional Extended Integration information is filled in.  

There is an issue we are aware of in 2.4.8.0 where this information can get wiped occasionally, in which case it needs resetting as described above