DEV Community

Marcos Henrique
Marcos Henrique

Posted on

The safest way to download a private repository

Introduction πŸ•΅πŸ»β€β™€οΈπŸ•΅πŸ»

I'm writing a script to easily download a code stored in a private repository from the command line.
Many solutions to this was exposing credentials in the command line, personally, I didn't want to put my password into my script to accomplish this.

If you're the type to live dangerously and don't care about security, use the following:

curl --digest --user <username>:<password> https://bitbucket.org/<username>/<repository>/get/<branchname>.zip -o <branchname>.zip
Enter fullscreen mode Exit fullscreen mode

But if you're like me and care about the security of your applications, let's get down to business

Set up an SSH key πŸ‘©β€πŸ”§ πŸ‘¨β€πŸ”§

The first step is create private and public keys, I won't go into the details of how to do this, as we have the tutorials on github and bitbucket extramement explicit and clear on how to do this in the best way:

The magic command πŸ§™β€β™‚οΈπŸ§™β€β™€οΈ

I'll assume that you already have your keys configured, so just run the command below:

git archive --remote=ssh://git@bitbucket_or_github.org/your_username/your_repository.git --format=zip --output="zip_file.zip" desired_branch
Enter fullscreen mode Exit fullscreen mode

Discussion (0)