how to wget a github file

The general problem is that github typically serves up an html page that includes the file specified along with context and operations you can perform on it, not the raw file specified. Tools like wget and curl will just save what they're given by the web server, so you need to find a way to ask the web server, github, to send you a raw file rather than an html wrapper. This is true whether you use -o -O or >>. The "...//raw.git..." address in this particular test case is probably serving raw files, and pre-solving the OP's problem as posted, which is why all of these answers work, but don't solve the more generic problem. I can download a text file, or an html-wrapped version of it from the following urls. Note the differences between them and feel free to paste them in a new tab or new window in your browser as well.

html-wrapped, default:

https://github.com/raspberrypi/linux/blob/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig

raw link, if you right-click the [raw] button on the html page:

https://github.com/raspberrypi/linux/raw/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig

final url, after being redirected:

https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig

You can then download with either:

wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig
curl https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/arch/arm/configs/bcmrpi_defconfig -o bcmrpi_defconfig

The simplest way would be to go to the github page of the content you want and right-click to get the [raw] link for each file. If your needs are more complex, requiring many files, etc. you may want to abandon wget and curl and just use git. It is probably a more appropriate tool for pulling data from git repositories.


It looks like there is a certificate problem, ie:

certificate common name 'www.github.com' doesn't match requested host name 'raw.githubusercontent.com'

If you trust the actors involved, then you can ignore this by adding the wget argument: --no-check-certificate.

Tags:

Wget

Github