Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Main/Master mismatch between local and remote repositories

I initialized a new repository in Bitbucket, which created a 'main' branch. Then, using the Salesforce DX plugins in VS Code, I created a local copy of our Salesforce test environment in VS Code.

In VS code, my repository's primary branch is called 'master'. When I push from VS code to Bitbucket, instead of pushing onto the 'main' branch, it creates a new 'master' branch. So now I have 'main' and 'master'.

I eventually figured out how to merge 'master' into 'main', but the very next time I tried to push again from VS code into bitbucket, it created another 'master' branch instead of adding to 'main'.

Additionally, bitbucket says I have no repositories found in this workspace, although I have authorized bitbucket.

How do I change either Bitbucket or my local git repository so that the names of the branches match each other?

1 answer

1 accepted

1 vote
Answer accepted

Hi Josh and welcome to the community.

First, allow me to say that I am not very familiar with VS Code. Most Git GUI applications offer the ability to set which remote branch a local branch is tracking. If you can see a list of branches in VS Code, perhaps right-clicking the 'master' branch will show you and give you the ability to change the remote tracking branch to 'main' instead of 'master'.

From the description of your issue, it sounds like your local branch 'master' is tracking a remote branch named 'master', which would explain why pushing 'master' branch creates a 'master' branch in the Bitbucket repo.

If you don't see an option to change this from VS Code, I can let you know how to change this from command line:

If your want your local branch 'master' to track the remote branch 'main', you can open a command line tool/Git Bash, navigate to the directory of the repo, and then run the command:

git branch master -u origin/main

If you want, you can also rename your local branch to main, to avoid any confusion. First, make sure that 'master' branch is checked out locally. Then, rename it to 'main' with the command

git branch -m main

and set origin/main as the remote tracking branch with

git branch main -u origin/main

The commands above assume that the repo's remote is named 'origin', which is the default name created for a remote.
You can confirm if this is the case for your repo by running the command

git remote -v

If you see in the output

origin <bitbucket_repo_url> (fetch)
origin <Bitbucket_repo_url> (push)

then this confirms the remote's name is indeed origin. If you see a different name, you'll need to use that one instead of 'origin' in the commands above.

Please feel free to let me know if this helps and if you have any questions.

Kind regards,

This was a wonderfully detailed reply, thank you so much. I'm new to git so the commands are very helpful.

I'm still a little confused about which url should be considered the "correct" url for a Bitbucket repository.

In the web browser, the url to the repository looks like:

however if I click the "clone" button it pulls up a url that looks like

I had set the one with .git as the origin, so now I have a remote "main" that looks like the first url and a remote origin that looks like the second. I don't know if I can or should change the url associated with origin or if it doesn't really matter.

Hi Josh,

When you open a repository in your browser, the URL is indeed

If you click the Clone button, then the clone command for HTTPS authentication (username+password) will look like this indeed

It includes your own Bitbucket username, and that URL is set as a remote in your local clone. This way, you will not be asked to enter your Bitbucket username every time you pull from or push to the Bitbucket repo from your local one.

There is no need to change the origin if the URL looks like, this is correct.

I am a bit confused also about the remote 'main' that you mentioned. If you execute the command

git remote -v

do you see a remote named 'main' listed in there?

There is no need to set a second remote named 'main'. You just need to set your local branch named 'master' (or 'main', if you have renamed your local branch), to track the remote branch origin/main.

If there's still confusion/issues and you haven't managed to resolve this, could you let me know what is the output of the following commands in your local clone?

git remote -v
git branch -a
git branch -vv

Please feel free to sanitize the URLs in the output of the first command prior to sharing it, but leave the branches names in the output of the last two commands if that's ok, so we can check what the current status of the branches are.

Kind regards,

Thank you again for your help! I did rename my local branch to 'main'. When I run the git remote -v command, this is what I see:

main (fetch)
main (push)
origin (fetch)
origin (push)
origin (push)

So it looks like I have a main and an origin. The other weird thing is it looks like my last 2 lines are identical, I'm not sure if it's supposed to be that way or not.

git branch -a produces

* main

and git branch -vv produces

* main b4409b8 more formatting of class getPOPtest

Also, when I run "git push main" I can see in Bitbucket that my push succeeded.

Hi Josh,

Thanks for the info!

I don't believe that you need the remote 'main', mentioned in the output of 'git remote -v'.
What is configured there is the remote repository (and not the remote branches), so just 'origin' should be ok.
You may remove the remote 'main' with the following command inside the repo directory:

git remote rm main

I am not sure why there are two lines with

origin (push)

Normally there should be only one. You can try removing and re-adding the remote 'origin', to see if this helps fix the issue:

git remote rm origin
git remote add origin

It's also strange that git branch -a doesn't list the remote branches as well, normally you'd see something like

* main

You can try running the following command again, after you sort out the remotes:

git branch main -u origin/main

It looks that there are no issues now since the push succeeds, but I'd still suggest sorting out the above, just to make sure that the set up is correct.

Please feel free to let me know if you have any questions!

Kind regards,

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

2,567 views 1 9
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you