Download private BitBucket repository zip file using http authentication

I’m writing a script to easily deploy an application. The code for the application is stored in a private BitBucket repository.

I’d like to be able to download a zip file of the commit. I’ve tried authenticating with the following code:

  • How to push .txt.gz file to git
  • Move issues from Bitbucket to Github
  • How do I visualise my git repo properly?
  • git pull error “The requested URL returned error: 503 while accessing”
  • Bitbucket: Adding a local built project to bitbucket using a Mac OSX
  • what may happen if the size of my git repo on github exceeds 1GB?

    However, instead of accomplishing the task it redirects to the login page on BitBucket.

  • Git and Mercurial - can someone explain this test result
  • Git workflow tips
  • rsync git big repository
  • How can I get the equivalent of .hgignore's regular expressions ^var/(?!\log|.dummy) and ^var/log/(?!\.dummy) in .gitignore?
  • Unable to checkout git submodule path
  • Sourcetree does not launch Beyond compare external merge tool
  • 6 Solutions collect form web for “Download private BitBucket repository zip file using http authentication”

    In order to download a zipped copy of a private Bitbucket repository from the command line, use the following:

    curl --digest --user <username>:<password><username>/<repository>/get/<branchname>.zip -o <branchname>.zip

    where <username> and <password> are the Bitbucket account name and password, <repository> is the repo name and <branchname> is the branch. If you’d rather download a specific commit, use the SHA-1 hash of the commit in place of <branchname>.

    The --digest flag is for your security, and is highly recommended. It accomplishes authentication so that your username and password are not sent in the clear. The -o flag sends the output of the curl command to disk as a file, instead of streaming across your terminal screen.

    Note: Bitbucket’s authentication scheme isn’t compatible with wget. That is why you must use curl.

    For public Bitbucket repositories the command is:

    curl<username>/<repository>/get/<branchname>.zip -o <branchname>.zip

    Or alternately, you may use wget for public repositories since no authentication is required:


    In addition to .zip format, you may download repositories in .gz and .bz2 flavors. Simply replace .zip in the code above with either .gz or .bz2to download the repository in the compressed format of your choice.

    Personally, I didn’t want to put my password into my script to accomplish this. So the trick was to run the following command, after adding your public key to your bitbucket account:

    git archive --remote=ssh:// --format=zip --output="" master

    I have multiple keys on my system, if you do too, you will want to create a config file within your ~/.ssh directory that specifies to use a specific key for bitbucket connections.


      StrictHostKeyChecking no
      IdentityFile /home/me/.ssh/my_private_key

    The –digest flag is for your security, and is highly recommended. It accomplishes authentication so that your username and password are not sent in the clear.

    This not true.

    Bitbucket exclusively uses TLS and so at no point does anything go over the wire in clear text. As a result, Digest provides no benefit over Basic Auth. In fact, considering that Digest is server-initiated, you incur an additional server round-trip requesting the server-provided nonce.

    Our use of Digest has been redundant and deprecated ever since we stopped offering unencrypted HTTP access several years ago and was kept only because there were curl-based scripts doing --digest as suggested by @GrowlTiger.

    In fact, we are about to turn off Digest altogether on May 1st, after which curl --digest will cease to work.

    More info can be found:

    For those who want to download single file from private repo on bitbucket, I’ve tried the above but none worked. Finally I got it working with the below command:

    wget --user=<user> --password=<password><user>/<repo>/raw/master/<filename>

    GrowlTigers answer is great, just an update: with wget it seems to work now, too:

    wget --user=<username> --password='<password>'<user>/<repo>/get/<filename>.tar.gz

    Does the tool you’re using support basic authentication credentials in the URL? Curl request with digest auth in PHP for download Bitbucket private repository strongly implies that:

    curl --user user:pass >


    Git Baby is a git and github fan, let's start git clone.