EmailThis Premium lets you save unlimited bookmarks, PDF, DOCX files, PPTs and images. It also gives you a PDF copy of every page that you save. Upgrade to Premium → Is it possible to create a new repository in Bitbucket by using command line Git? I have tried the following: git clone --bare https://username@bitbucket.org/username/new_project.git I get this message: Cloning into bare repository 'new_project.git'... fatal: https://username@bitbucket.org/username/new_project.git/info/refs not found: did you run git update-server-info on the server? It would be nice to do this without going to the web app. Jay Patel 19.7k1111 gold badges5555 silver badges7070 bronze badges asked Dec 9 '12 at 14:50 PatrickPatrick 8,0991818 gold badges7070 silver badges133133 bronze badges You can use the Bitbucket REST API and cURL. For example: curl --user login:pass https://api.bitbucket.org/1.0/repositories/ \ --data name=REPO_NAME to create new repository named REPO_NAME . See Use the Bitbucket REST APIs for more information. UPDATE For Bitbucket V2 specifically, see POST a new repo answered Dec 9 '12 at 15:24 MarekMarek 1,6231313 silver badges2020 bronze badges 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 . jay 4,83777 gold badges3333 silver badges5757 bronze badges answered Oct 29 '13 at 23:22 StephenStephen 2,64111 gold badge1616 silver badges2525 bronze badges Here is @hannesr's script tweaked a bit to accept input from prompts: # startbitbucket - creates remote bitbucket repo and adds it as git remote to cwd function startbitbucket { echo 'Username?' read username echo 'Password?' read -s password # -s flag hides password text echo 'Repo name?' read reponame curl --user $username:$password \ https://api.bitbucket.org/1.0/repositories/ \ --data name=$reponame \ --data is_private='true' git remote add origin git@bitbucket.org:$username/$reponame.git git push -u origin --all git push -u origin --tags } You should place this in your .bashrc or .bash_aliases . Michael 4,19033 gold badges4444 silver badges6565 bronze badges answered Sep 9 '14 at 19:47 pztrickpztrick 2,9252020 silver badges3333 bronze badges I made a quick shell script that takes care of creating a local git in current working directory, doing the "Initial commit" and then create the bitbucket repo (using Mareks curl method), and then finally doing all that is needed to push the initial commit to bitbucket. (note this is for private repos only but that is easily changed as described by Patrick) Use it like this: fillbucket <user> <password> <reponame> Code is on http://bitbucket.org/hannesr/fillbucket answered Feb 26 '14 at 13:28 hannesrhannesr 32933 silver badges1212 bronze badges The top answer with cURL wasn't working well for me, so I ended up doing it in Python with Bitbucket-API. Here's the documentation on the repository.create() call. Install: pip install bitbucket-api Python: >>> from bitbucket.bitbucket import Bitbucket >>> bb = Bitbucket(username, password) >>> bb.repository.create('awesome-repo', scm='git', private=True) (True, {u'scm': ...}) answered Aug 28 '15 at 6:10 gakgak 21.9k2121 gold badges102102 silver badges146146 bronze badges Here's the one-liner copy/paste candy: # This is Git's per-user configuration file. [alias] create = "!f() { curl -X POST -u YOUR_EMAIL_ADDRESS -H 'Content-Type: application/x-www-form-urlencoded' https://api.bitbucket.org/2.0/repositories/YOUR_USERNAME_OR_TEAM_NAME/$1 -d '{\"is_private\": \"true\", \"scm\": \"git\", \"project\": \"KEY_OF_PROJECT\"}' | jq '.links.clone[].href'; }; f" NOTE : You should update constants with your informations. This way your password is not stored into your .bash_history. It has to be a one-liner to fit inside your ~/.gitconfig file. Usage git create <repository_name> This either return null or your newly created repository addresses. You can remove the jq part if you can't / don't want to install it. Sweetness Cheers! EDIT : I had to replace Content-Type: application/json with Content-Type: application/x-www-form-urlencoded because somehow the -d flag now sets the header to the latter even if you specify you are sending json. cURL manual says: (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded. Compare to -F, --form. answered Mar 12 '18 at 11:06 LowinputLowinput 30422 silver badges77 bronze badges @hannester I forked and slightly modified your script. You had the incorrect remote url (you left your username in the script). Modified it to included Username and Password in the script file. And renamed, with instructions on how to add to path: https://bitbucket.org/oscarmorrison/newgit answered Aug 12 '14 at 10:58 I've made a slight modification to @pztrick above script. This new script should work the same, but it uses the newer 2.0 API: function startbitbucket { echo 'Username?' read username echo 'Password?' read -s password # -s flag hides password text echo 'Repo name?' read reponame curl -X POST -v -u $username:$password -H "Content-Type: application/json" \ https://api.bitbucket.org/2.0/repositories/$username/$reponame \ -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }' git remote add origin git@bitbucket.org:$username/$reponame.git git push -u origin --all git push -u origin --tags } You can place this in your .bashrc or .bash_aliases file (just like the original script). Note that it will also create this as a private repo. You can change "is_private": "true" to "is_private": "false" to make it a public repo. answered Nov 3 '18 at 1:56 Not the answer you're looking for? Browse other questions tagged git bitbucket or ask your own question. | | Please check the attached file. EmailThis was not able to extract useful content from the website. Hence, we have saved the webpage to a PDF file. You can find that attached along with this email. | | Upgrade to Premium Plan ✔ Save unlimited bookmarks. ✔ Save PDFs, DOCX files, images and Excel sheets as email attachments. ✔ Get priority support and access to latest features. | | | |
No comments:
Post a Comment