M BUZZ CRAZE NEWS
// news

How to download a GitHub repo as .zip using command line

By Jessica Wood

I am trying to download a .zip file from GitHub using the command line in Ubuntu. I am using wget command for it on a remote Ubuntu system.

I run wget <link> where <link> is the address bar link of the file which I want to download. It ends with archive.zip?ref=master.

Now, when I am executing the command, it is downloading a file with text/html type and not the .zip file which I want.

Please tell me how to get the link to be given as the parameter of wget. Right now, I am just copying the link address of the button (using right click) and writing that as a wget parameter.

12

4 Answers

It does work, if you use the correct URL.

For a GitHub repo, there's a zip at , so you can download it with:

wget 

This downloads the zipped repo for a given branch. Note that you can also replace the branch by a commit hash.

Using cURL

curl -L 

cURL's -L flag follows redirects - it's a default in wget.

Download a .tgz instead of .zip

You can also download a tarball with:

wget 
1

From the comments I saw you actually speak about GitHub.

It won't work like this because:

Downloading a project on GitHub causes the GitHub server to first pack your project as zip and than forwarding you to a temporary link where you get your zip ..

this link will only work for a certain time and than GitHub will delete your zip file from their servers..

So what you get with wget is just the html page which would forward you as soon as your zip file is generated.

As suggested use

git clone <optional local path where to store>

to download the git repo ... If for some reason (e.g. for transfer it to others) you need it explicitly as zip you still could pack it after cloning is finished..

2

2021 Update Download and unzip from GitHub Using wget

Will also expand and delete the archive. Just edit the REPLACE_ values and then copy/paste

zip

GH_USER=REPLACE_WITH_USER \
GH_REPO=REPLACE_WITH_REPO \
GH_BRANCH=REPLACE_WITH_BRANCH \
wget \
-O "${GH_REPO}-${GH_BRANCH}.zip" && \
unzip ./"${GH_REPO}-${GH_BRANCH}.zip" && \
rm ./"${GH_REPO}-${GH_BRANCH}.zip"

tgz

GH_USER=REPLACE_WITH_USER \
GH_REPO=REPLACE_WITH_REPO \
GH_BRANCH=REPLACE_WITH_BRANCH \
wget \
-O "${GH_REPO}-${GH_BRANCH}.tar.gz" && \
tar -xzvf ./"${GH_REPO}-${GH_BRANCH}.tar.gz" && \
rm ./"${GH_REPO}-${GH_BRANCH}.tar.gz"

I just did it, but make sure you're using the correct link with URL end with *.zip like what @Robin Métral said above.

The exact steps I did:

  1. Open GitHub repository.
  2. Right click the Download Zip link, and copy the URL.
  3. Use that copied URL with wget in terminal.

I believe GitHub server will accept wget request and treat it as same as request with browser.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy