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

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

How to create a new Repository in Bitbucket and code?

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 Apr 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

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 Apr 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?

 

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.

 

 

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

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.

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

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

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

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

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/"

Any luck with this?

 

I'm trying to do the same.

 

Thanks

Like Vladimir_Vukanac likes this

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/"}}

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?

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

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

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

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

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.

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

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.

@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?

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.

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.

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?

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

 

Thanks

Glad I could help!

Also to simply get information, use GET.

oh thank you.

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.

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

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

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

Suggest an answer

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

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,784 views 10 16
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