How to create a new Repository in Bitbucket and code?

davidp7 April 17, 2017

Hi,

I am new to Bitbucket.

My Admin has created a new Project PRS.  It's path is like http://server:port/projects/PRS. He said I can now be able to add code.

I need to create a Repository / folders like QA & PROD and add code in it. Could you please guide me in simple steps either through Git CMD or Git UI?

Thanks in advance.

David

 

 

5 answers

1 accepted

2 votes
Answer accepted
Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 17, 2017

Hi David!

You can find step by step instructions on how to create a repository using the Bitbucket UI at Creating repositories. If you prefer to do it through the Git CMD, you can read Setting up a repository.

Once you've done that, you'll start coding. In this other article you'll learn how to get started with Git and Bitbucket and how to push your code to Bitbucket, visit Getting started with Git and Bitbucket Server.

Also, if you'd like to use a Git client, you can install Sourcetree which is free and available for Mac and Windows.

I hope this helps, David. Let me know if you have any questions!

Cheers,

Ana

davidp7 April 18, 2017

Hi Ana!

Thank you very much! I will follow the steps.

I have a question : I dont see the option "Create Repository" from UI.  Can I be able to create a repository with command  line? (  assuming I dont have Project Admin Rights)

Thank you,

David

Ana Retamal
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 19, 2017

Hi David, when you click Repositories in the navigation bar, a menu will be displayed and you'll see your recent repos and the option to create a new one. If you can not see the Repositories button, you'll need to check with your admin if you have the right permissions. If you still don't see it, you can send a screenshot of what you see in your Bitbucket UI (remember to remove any sensitive information ;) )

If you prefer to do it via command line, you can use:

git init <directory>

That will create an empty Git repository in the specified directory. You can find more info at Setting up a repository.

Were you able to create a repository now?

 

davidp7 April 20, 2017

Hi Ana, Thanks for the reply.

I have followed up with my Admin to provide "Project Admin" access. Now, I am able to see the option and able to create the Repository.

Before "Project Admin" access is given to me, I have tried using Command line but unable to doit.

 

 

Jurgen Schober January 8, 2019

Is there a simple way to create a repo on the bitbucket server (self hosted) using the git (bash) shell script? I want to split folders into single repos and create those from a script. 

Like # people like this
Beatrix Ducz March 17, 2021

Hi, 

I think the answer shouldn't have been accepted as a solution, since it is not done from the cli. Git init creates a local git folder, doesn't create a remote on bitbucket.

It is hard to create a repo on bitbucket and then clone it and then copy the application files over. I don't see how is this called convenient. There should be a way similar to github, to create and then connect the repo to an existing project, and that should be a copy-paste similar to github new repo site. If something is working I don't see why change it.

 

  • git init .

  • git remote add origin <repourl>

  • git add .
  • git commit -m "Initial commit"

Thank you.

4 votes
Jonathan Leaders May 1, 2019

More recently, we can just use bitbucket-cli.

Install it using pip

pip install bitbucket-cli

Then create a repo using

bitbucket create --private --protocol ssh --scm git YOUR_REPO_NAME

Note that this creates a private git repo, you can use --public for public access and --scm hg if you use Mercurial. Username argument can be added via --username YOUR_USER_NAME.

Thanks to Stephen

Rob Record July 12, 2019

I've been using this but the APIs are suddenly deprecated.

Does anyone have an alternative? I miss it so much!

Jonathan Leaders July 12, 2019

Email the owner Zhehao and ask him to update it OR open source it https://pypi.org/project/bitbucket-cli/

anvitaindiatech December 4, 2019

This API is no longer supported.\n\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"

EVO_9 March 29, 2020

Any luck with this?

 

I'm trying to do the same.

 

Thanks

Like Vladimir_Vukanac likes this
Serkan Sunel January 17, 2021

Request Error 410: gone
{"type": "error", "error": {"message": "Resource removed", "detail": "This API is no longer supported.\n\nFor information about its removal, please refer to the deprecation notice at: https://developer.atlassian.com/cloud/bitbucket/deprecation-notice-v1-apis/"}}

2 votes
Vladimir_Vukanac April 3, 2020

Any news on this?

As a community, maybe we can together take over the project and update to new API version?

At least just for creating a new repo.

What do you say?

Will Hartzell-Baird April 3, 2020

I believe that the problem is that the new API on the backend does not support this functionality.

robrecord April 3, 2020

Actually it does - I was able to use the new API with curl to create new repositories and projects.

robrecord April 3, 2020

Vladimir, it's a great idea. (I don't have the time or the skills right now, unfortunately.)

Vladimir_Vukanac April 3, 2020

Can you share specific link for the curl you have used?

EVO_9 April 3, 2020

Please share.

 

I would love to get together but I am no where near good enough to contribute having only just started using git never mind learning how apis work.

robrecord April 14, 2020
curl -X POST -u your_username:access_token_or_app_password -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/teams/your_team_name/projects/ -d '{"name": "ABC Project", "key": "ABC", "description": "ABC project description", "is_private": true}' | jq .


curl -X POST -u your_username:access_token_or_app_password -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/repositories/team_name_or_username/repo_name -d '{"is_private": true, "scm": "git", "project": {"key": "ABC"}}' | jq .
Like # people like this
robrecord April 14, 2020

Just to describe these two above: the first creates a project, and the second creates a repo inside that project.

Also, in the second one, you're telling bitbucket the URL that you would like it to be available at, and it doesn't matter that the "repo_name" endpoint doesn't exist yet.

If you don't have jq installed you can omit the "| jq ." bit at the end; it just deciphers the response.

Lastly, if you're not using a team, you may need to edit the first URL slightly - see the API documentation

If you're not using projects, omit the first request, and remove the "project: {"key": "xyz"}," part in the json in the second request.

I used the Postmaster app to help me formulate and reuse these calls.

EVO_9 April 15, 2020

@robrecord 

 

Thank you for that.

 

I'm struggling with this, could you help me a little more please.

 

I'm a solo designer, I don't work with teams at the moment but I have setup a team to try and get this to work.

I'm currently using your second piece of code minus a few bit as mentioned in your description. See below:

curl -X POST -u myusername:123456789 -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/repositories/myteam/repo_name -d '{"is_private": true, "scm": "git"}'

 

When I paste that code into MacOS Terminal and nothing happens. I check Bitbucket after and nothing has been added.

 

To setup my API (OAuth) I just gave it a name, ticked all permissions but I thought this was enough to get it to work.

 

What am I doing wrong?

robrecord April 17, 2020

Hi, you're doing great! You've written it correctly -- actually you don't need a team if it's just yourself, you could replace the team name with your username -- but if you're getting no response then it probably doesn't like the key you're giving it. I just tested and if I mistyped the key I received no response at all.

I'm very sorry but I gave the wrong info before. It's not an API key that's needed here, but an authorisation token - that's a complicated thing to produce for this purpose so in its place you can use an app password.

Go to your bitbucket settings, click App Password (under Access Management) and create a new app password - call it command line API or whatever you like. You can use this password in your API requests.

Hope that helps, sorry about the misinformation.

robrecord April 17, 2020

If you're going to do this a lot, and are using a unix-based system like macos or linux, you can install jq (with homebrew it's `brew install jq`) to make the output more readable.

EVO_9 April 17, 2020

Thank you

 

Installed an app password and it now works for both teams and as a solo repo.

 

I've also installed jq which helps.

 

Thank you for your help.

 

P.S Is there a way to delete a repo using the same way?

EVO_9 April 17, 2020

Don't worry, just needed to replace POST with DELETE

 

Thanks

robrecord April 17, 2020

Glad I could help!

Also to simply get information, use GET.

EVO_9 April 17, 2020

oh thank you.

Vladimir_Vukanac April 20, 2020

Looks like you guys liked only curl idea, which is probably the perfect solution for the start. Do you think we need to expand it to a CLI client? If yes, what would be the prefered way for you to use it and to install it (pip, npm -g, composer --global, brew)?
We need to explain also how to authenticate.

Yellappa M January 9, 2021

Thank you @robrecord  for the solution. This saves a lot of time.

0 votes
Andres LeonRangel May 18, 2020

Hey guys this is not working for me. i am getting this:

{
"type": "error",
"error": {
"message": "Forbidden"
}
}

 but in the AppPassword i can see my access. 
i can use the GET method as in

curl -X GET -u MyUSER:$ADMIN_TOKEN -H 'Content-Type: application/json' https://api.bitbucket.org/2.0/teams/MyUSER/projects/ | jq .

 

Please help

0 votes
robrecord April 3, 2020

Posted this in error (there is no delete function?!)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events