¿Crear un nuevo repositorio en Bitbucket desde el terminal Git Bash?


¿Es posible crear un nuevo repositorio en Bitbucket usando la línea de comandos Git? He intentado lo siguiente:

git clone --bare https://[email protected]/username/new_project.git

Recibo este mensaje:

Clonando en el repositorio desnudo 'new_project.git'...
fatal: https://[email protected]/username/new_project.git/info/refs no encontrado: ¿ejecutaste git update-server-info en el servidor?

Sería bueno hacer esto sin ir a la aplicación web.

Author: Jay Patel, 2012-12-09

8 answers

Puede usar la API REST de Bitbucket y cURL. Por ejemplo:

curl --user login:pass https://api.bitbucket.org/1.0/repositories/ \
--data name=REPO_NAME

Para crear un nuevo repositorio llamado REPO_NAME.

Consulte Use las API REST de Bitbucket para obtener más información.

ACTUALIZAR

Para Bitbucket V2 específicamente, ver PUBLICAR un nuevo repo

 85
Author: Marek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-10 19:03:11

Más recientemente, podemos usar bitbucket-cli.

Instalar usando pip

pip install bitbucket-cli

Luego crea un repositorio usando

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

Tenga en cuenta que esto crea un repositorio git privado, puede usar --public para acceso público y --scm hg si usa Mercurial. El argumento Username se puede agregar a través de --username YOUR_USER_NAME.

 41
Author: Stephen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-10-21 10:42:56

Aquí está el script de@hannesr ajustado un poco para aceptar la entrada de mensajes:

# 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 [email protected]:$username/$reponame.git
    git push -u origin --all
    git push -u origin --tags
}

Debe colocar esto en su .bashrc o .bash_aliases.

 10
Author: pztrick,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-09-19 20:34:32

Https://confluence.atlassian.com/bitbucket/repository-resource-423626331.html

$ curl -X POST -v -u username:password -H "Content-Type: application/json" \
  https://api.bitbucket.org/2.0/repositories/teamsinspace/new-repository4 \
  -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'
 7
Author: mcfw,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-11-11 17:38:18

Hice un script de shell rápido que se encarga de crear un git local en el directorio de trabajo actual, hacer el "commit Inicial" y luego crear el repositorio de bitbucket (usando el método Mareks curl), y finalmente hacer todo lo necesario para enviar el commit inicial a bitbucket.

(tenga en cuenta que esto es solo para repositorios privados, pero que se cambia fácilmente como lo describe Patrick)

Úsalo así:

fillbucket <user> <password> <reponame>

El código está encendido http://bitbucket.org/hannesr/fillbucket

 2
Author: hannesr,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-26 13:28:41

Aquí está el caramelo de una sola línea de copiar/pegar :

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

NOTA: Debe actualizar constantes con sus informaciones.

De Esta manera su contraseña no se almacena en su .bash_history .

Tiene que ser de una sola línea para caber dentro de su archivo ~/.gitconfig.

Uso

git create <repository_name>

Esto devuelve null o sus direcciones de repositorio recién creadas.

Puedes elimine la parte jq si no puede / no desea instalarla.

Dulzura

Mensaje de Éxito

Salud!

EDIT: Tuve que reemplazar Content-Type: application/json con Content-Type: application/x-www-form-urlencoded porque de alguna manera la bandera -d ahora establece el encabezado a este último incluso si especifica que está enviando json.

El manual de cURL dice:

(HTTP) Envía los datos especificados en una solicitud POST al servidor HTTP, de la misma manera que un el navegador lo hace cuando un usuario ha llenado un formulario HTML y presiona el botón enviar. Esto hará que curl pase los datos al servidor usando el tipo de contenido application / x-www-form-urlencoded. Comparar con -F, form form.

 1
Author: Lowinput,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-07-29 08:36:10

La respuesta superior con cURL no funcionaba bien para mí, así que terminé haciéndolo en Python con Bitbucket-API. Aquí está la documentación del repositorio .create () call.

Instalar:

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': ...})
 0
Author: Gerald Kaszuba,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-28 06:10:47

@hannester bifurcé y modifiqué ligeramente tu guión.

Tenía la url remota incorrecta (dejó su nombre de usuario en el script). Modificado para incluir Nombre de usuario y contraseña en el archivo de script.

Y renombrado, con instrucciones sobre cómo agregar a la ruta:

Https://bitbucket.org/oscarmorrison/newgit

 -1
Author: Oscar Morrison,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-12 10:58:49