Cannot push from Sourcetree to Bitbucket
Asked by Vito Kurnik:

I can't push from Sourcetree to Bitbucket even though I added a remote repository and I entered the right username and password.


Answers:
author: Vito Kurnik
body: Hi [@Mikael Sandberg](/t5/user/viewprofilepage/user-id/853579)

I'm back with an old familiar problem. I'm working on a group project and our Bitbucket repository was created a few weeks ago. I tried to clone it and set the destination path to my Unity project folder, but I couldn't - it said I need to choose or create an empty folder. I've decided to create a new local repository in Sourcetree and add our Bitbucket repository as a remote repository. But, when I tried to push, the old "invalid username or password" error message appeared, even though I deleted the passwd file and removed any credential related to Bitbucket.

I know I could just clone our Bitbucket repository into an empty folder but then I'd had to move all my files from the Unity project folder into that folder and that would be exhausting. Any ideas on how to manage the situation?

comments: author: Mikael Sandberg
body: Make sure your password is not stored in the Windows Credential Manager too. I would recommend that you use an SSH key instead, that way you do not have to worry about passwords. Your other option is to turn off Windows Credential Manager and see if that helps.

`git config --system --unset credential.helper`  
`git config --global --add core.askpass` `""`

The first command disables Credential Manager for Git, the second one turns it off for openSSH.


author: Vito Kurnik
body: For anyone wondering: you will probably find your answer somewhere in the replies to the one I marked as "accepted".


author: Vito Kurnik
body: ![bitbucketsucks.png](https://community.atlassian.com/t5/image/serverpage/image-id/70725i8B8387F6AF369D40/image-size/large?v=v2&px=999 "bitbucketsucks.png")That is what I got. Here's what went down:

1. I created a new repository on Bitbucket. The "master" branch also got created in the process and it included the README.md file.

2. I then made a new repository on my computer using Sourcetree. I committed a few files and they were all in the "master" branch.

3. I added a remote repository in Sourcetree which was, of course, the one I created earlier on Bitbucket.

4. I tried to push to Bitbucket the files I just committed to the "master" branch in Sourcetree.

5. After that failed I pulled from Bitbucket (it was only the README.md file).

6. After multiple attempts, I couldn't push the files from Sourcetree to the Bitbucket repository into the "master" branch. But then I made a "new" branch and it worked but I wanted the files from Sourcetree to be in the "master" branch in Bitbucket. I tried to merge the two branches on Bitbucket but I couldn't because they're unrelated.

Apart from the error message screenshot, I'm also adding the screenshots from Sourcetree and Bitbucket.![srctree.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/70732iBDE759080E018C6C/image-size/large?v=v2&px=999 "srctree.PNG")![bb1.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/70731i1661CF522277F489/image-size/large?v=v2&px=999 "bb1.PNG")![bb2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/70733iA40578B697FDA953/image-size/large?v=v2&px=999 "bb2.PNG")

comments: author: Mikael Sandberg
body: Okay, so the first error message indicate that your username or password is incorrect, so you should make sure that the password stored in Sourcetree and Windows Credential manager is correct.


author: Vito Kurnik
body: I made sure of that but even after that, I wasn't able to push the files which I committed to the "master" branch in Sourcetree to the "master" branch in Bitbucket. I didn't capture that error message though - I hope you might still be able to help me anyway considering my description of what went down.


author: Mikael Sandberg
body: There are lots of things that can prevent you from pushing to a specific branch, for example branch permissions, hooks, etc. Do another push of master and see what error message you get.


author: Vito Kurnik
body: ![error2.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/70879i3D80D66E66DAFD08/image-size/large?v=v2&px=999 "error2.PNG")That's what I get. Even after I performed the action "pull" (a few days ago when this problem occurred and I had to "make a compromise" to finish my school work) I still couldn't get the files to be pushed into the "master" branch on Bitbucket. It was sort of untouchable, so to speak. And the only way to not get the invalid username/password error for me is to include username:password in the link to the repository on Bitbucket which isn't very private since I have to take screenshots for my school work. I was trying to sort things out in Sourcetree in Authentication bar in Tools\>Options, but these credentials, or whatever you want to call them, confuse me, the whole process does.

All want to know (with simple and plain instructions, not like those tutorials where they just go on blabbing about this and that and so on) is how I can create a repository on Bitbucket, create a remote repository in Sourcetree so I can push to the repository on Bitbucket (to any branch I desire) and how to set the credentials right so that I don't have to deal with any errors.

Thank you in advance.


author: Mikael Sandberg
body: I think I know what got you into this issue in the first place, you created a new repository locally instead of cloning the remote repository. This would also explain why you could not merge your changes into master in Bitbucket.

Okay, so here is the simple guide you are looking for to create a repository and clone it:

1. In Bitbucket, create a new repository.
2. Clone the repository, either by copying the URL or by clicking Clone in Sourcetree
3. Add your files to the repository and commit them
4. Push everything back to Bitbucket


author: Vito Kurnik
body: Believe it or not, I've tried that before as well. But, a familiar error message appeared:![cloningerror.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/70882i1DB503A262568807/image-size/large?v=v2&px=999 "cloningerror.PNG")


author: Mikael Sandberg
body: So try this, go to c:\\users\\\<your user ID\>AppData\\local\\atlassian\\sourcetree and remove the passwd file. Then go to Credential Manager (under control panel) and remove any references to Bitbucket. If you now do another clone you should be asked to enter your Bitbucket password.

You could also try and setup a SSH key, that way you do not have to deal with usernames and passwords for Bitbucket. You can find the instructions on how to do that here: <https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html>


author: Vito Kurnik
body: Thank you! I know this was a lengthy back and forth discussion but I was able to clone the repository, commit files and push to Bitbucket with no problem. Thank you again :)


author: Mikael Sandberg
body: You are most welcome, glad it got solved!


author: Tien Le
body: Darn! Even tried restarting laptop and Sourcetree is still wanting to log in with username and password (after setting up SSH key successfully) and fails. Now what? Thanks,

Tien


author: Mikael Sandberg
body: Hi [@Vito Kurnik](/t5/user/viewprofilepage/user-id/3612781),

Welcome to the Atlassian Community.

Do you get an error message when you try and push? And if so, what is that error message?

comments: author: Vito Kurnik
body: Hi, [@Mikael Sandberg](/t5/user/viewprofilepage/user-id/853579) I have included the error message screenshot and some other details in my answer down below.


Tags: bitbucket