Create new repo on Bitbucket from Git Bash terminal?

前端 未结 7 2198
半阙折子戏
半阙折子戏 2020-12-22 19:53

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         


        
相关标签:
7条回答
  • 2020-12-22 20:15

    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.

    0 讨论(0)
  • 2020-12-22 20:21

    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.

    0 讨论(0)
  • 2020-12-22 20:23

    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" }'
    
    0 讨论(0)
  • 2020-12-22 20:28

    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

    0 讨论(0)
  • 2020-12-22 20:29

    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': ...})
    
    0 讨论(0)
  • 2020-12-22 20:36

    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

    0 讨论(0)
提交回复
热议问题