Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,361,338
Community Members
 
Community Events
168
Community Groups

how to push code to the existing bitbucket repository first time using sourcetree ?

Deleted user Feb 25, 2020

Hi,

i have an exitsing code on my local drive and i have created a empty (new ) repo in the bit bucket. now i want to push the code to the repo using the source tree.  i dont want to clone to a new folder and copy the files allover instead i want to commit the existing folder to the repo using source tree not the command line way. Please let me know if anyone has a solution to this.

2 answers

Following on @blaiseli , the instructions above, and the Bitbucket default, is incorrect. You must have a completely bare repository to avoid a failed operation.

So, steps are

  • When creating the remote repository on Bitbucket, DO NOT create ANY files, No readme, no gitignore, or anything else that might be suggested.
  • Then execute commands locally:
git remote add origin <the URL for your Bitbucket repository> 
git push -u origin master

Or you can a force push, which will wipe out all existing files on the new repo

 

git push -u origin master --force

Like # people like this
3 votes
Mikael Sandberg Community Leader Feb 25, 2020

Hi @[deleted],

Welcome to Atlassian Community.

There should be instructions for how to populate your repository with local code shown if you access your repository in Bitbucket, but here are the steps:

  1. Cd into your directory that have your code
  2. Initiate it as a Git repository by running these commands
    git init
    git add --all
    git commit -m "Initial Commit"
  3. Copy the URL for you empty repository in Bitbucket
  4. Set the remote URL for your repository and push your initial commit
    git remote add origin <the URL for your Bitbucket repository> 
    git push -u origin master

Done, you should now see your code in Bitbucket.

Like Nicholas Liong likes this

> There should be instructions for how to populate your repository with local code shown if you access your repository in Bitbucket

 

There apparently isn't when keeping the default option (include a .gitignore). And then, then the instructions fail (fatal: refusing to merge unrelated histories).

 

In my case, I had to delete the new repository and create another one, making sure there was no .gitignore. Then the instructions appeared and worked.

Like # people like this

@Mikael Sandberg Where are the instructions? Github has it indeed.

Is there a way to edit responses?

This page is one of the first google results. But the method given here has been outdated for some time.

Like Nigel Pepeon likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Sourcetree

Bug Fix: Sourcetree for Windows authentication error when updating to app password

Hello Sourcetree users!!! With the recent removal of Bitbucket Cloud account passwords for app passwords (please see our Bitbucket Cloud community post for details on why we made this change for se...

79,146 views 135 29
Read article

Atlassian Community Events