Update 2014-08-16: The method described below no longer works. For historical reasons, I will be leaving the post as-is; for an updated how-to on the subject, please refer to this StackOverflow answer.

Let’s face it. Some of the biggest projects on the internet are flocking to github. But what if you have a top-secret project using a private repo, and you want to programmatically fetch builds? The github API is a great way to interact with your repositories without touching your browser. Despite having documented methods for controlling private repositories (through different scope levels of oAuth tokens), there is no information on how to download files from private repos for authorized users, so without any further delay, here’s how to do it!

CURL:

curl -L -F "login=$USER" -F "token=$TOKEN" https://github.com/$USER/$REPO/$PKGTYPE/$BRANCHorTAG

Some quick notes: the -L flag tells curl to follow redirects (which will occur after you github sees you authenticating)

The -F flag is simply used to define POST data.

Variables for you to switch out:

$USER with your username — in the URL part of the command, the $USER may be different if you are downloading from a github organization repo that you have access to. Be sure the first $USER in the command is the account you have a token for.

$TOKEN with the api token on your github profile. This is not to be confused with any oAuth tokens you have generated yourself for use with the github API

$PKGTYPE can be zipball or tarball.

$BRANCHorTAG can be a branch, like master, or a tag for a commit you have made.

That should be all you need to know to get going!