Github is the world’s largest platform for putting your source code online and sharing it with the world. It’s pushed out competitors like Google Code, which closed down a couple of years ago. As a result, most projects are now hosted on Github and if you want to download the source code of some project, you should know how to use it.
The basic premise of GitHub is of course, git. It’s what is known as a “version control system” and if you need to develop any kind of app with source code, it’s an invaluable tool – along with others like SVN. But git seems to be the new standard. I use it myself when developing applications, and it’s invaluable.
However, it’s a new tool and not everyone who wants to work with code should need to know how to use git, or even install it on their own computer. The recommended way to obtain code from github onto your own PC is to “clone” a repository. But in this article, I’m going to show you how to bypass that and simply download the source code directly onto your Linux or Windows machine. Let’s start with downloading the complete source code of a project to start with.
Downloading the Complete Source Code of a Project from GitHub
Let’s say you see a project on GitHub and want to fork it or compile it separately on your own system. As mentioned above, the recommended way is to clone the git repo, but if you just want the source code without any of the hassles or extra tools, follow these steps.
Step 1: Find the Project Page on GitHub
For this example, let’s take one of my own projects that I migrated over to GitHub when Google Code was shut down. At my profile page, you can see the various pieces of code that I’ve put up online for public viewing:
Clicking this will take us to the project page with a list of all the files and folders available with the source code. From here, we can get a snapshot of everything that has happened with our project. The number of pull requests, commits, etc etc.
Step 2: Getting the Download Link
On the top right, we can see a green button labeled “Clone or download”. Clicking this shows us the git repo that we can obtain. But this is not what we’re interested in. Rather, right click the blue button called “Download Zip” and copy the link address.
Now we simply download this file. In Linux for example, we can just type in:
wget [link to zipped source file]
Replace [link to zipped source file] with the URL we just obtained, and the system will download the file into your current folder like this:
This will be in the form of a .zip file. We can unzip it using the following command:
And this will recreate the entire directory structure within our current directory:
And that’s how we get the entire source code from GitHub. But what if we’re interested in just a single file?
Downloading a Single file from GitHub
Let’s say we’re interested in just one particular file instead of the entire source code. In that case, navigate to the file within the project on the GitHub website. When you see the contents of the file, right click the button on the top right called “Raw”, and copy the link address as before:
And now like before, download it onto your local system:
wget [link to individual file]
You can see below that after executing this command, I have the requested file in my current directory:
And that’s how we download entire projects, as well as individual files from GitHub into Linux!