Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Unable to create a new branch in a repo using Bitbucket API 2.0

I want to create a new branch named test-branch-name from the master branch in a given repository. So as per the documentation provided here, I tried creating a new branch in the repository using Postman.

curl --location --request POST 'https://api.bitbucket.org/2.0/repositories/<workspace>/<repo_name>/refs/branches' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <auth_token>' \
--data-raw '{
    "name" : "test-branch-name",
    "target" : {
        "hash" : "default"
    }
}'

With above-mentioned request, I get this response.

{
    "type": "error",
    "error": {
        "fields": {
            "target.hash": "Commit not found: default"
        },
        "message": "Bad request"
    }
}

If, instead of the default hash, I put the full commit hash of the latest commit from the master branch in the request payload, the API call creates the branch from develop branch and not from master.

What am I missing?

1 answer

1 accepted

1 vote
Answer accepted

Hello @Akshay Maldhure,

Welcome to the Community!

A branch in Git is a pointer to a commit. Bitbucket needs to understand which commit you want to create the branch at. So the value of hash should be something identifying a commit. This can be its hash, a tag or a branch name. You get the error because your repository doesn't have any branches or tags called default, and obviously it's not a valid commit hash too.

As for master vs develop problem when using hash you mentioned, this shouldn't happen. Can you double check you used the right commit hash? The only other explanation I can think of is that master and develop point at the same commit, but I guess that's not the case.

If you're sure you used the right hash, and you still get the branch created at the wrong place, do you mind opening a support case with us and pointing there to the repo in question and dumping commands you ran with their outputs?

Cheers,
Daniil

If, by making sure about using the right hash, you mean going to https://bitbucket.org/libertywireless/<repository_name>/commits/branch/master, clicking on the latest commit and using the full commit has which appears in the browser's address bar, then yes, I'm sure I'm using the right hash. I've created a support request https://getsupport.atlassian.com/servicedesk/customer/portal/11/BBS-128678 for this issue.

Like Daniil Penkin likes this

Suggest an answer

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

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

503 views 6 4
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