Hi, welcome, this is Clemens at Elektor. In this video I will show you how to
download something from GitHub. If you use microcontrollers, play with Arduino or
do other things that involve open source software, you will most certainly have
come across GitHub. GitHub has become _the_ place for people to share
source code for all sorts of open source applications, ranging from simple single-file Arduino sketches to
huge cloud applications consisting of thousands of files, but also other things like electronics
design files or simply text documents. GitHub is a hub for Git. Git is a so-called versioning system which means that it keeps
track of changes made to the documents that it knows of. The main purpose of Git and GitHub is to allow groups of
people to work together on the same software project.
Because GitHub is a tool for professionaland
production quality software development, it has lots of functions and options
that most people never need, and that make
it complicated. At Elektor also we publish our code on GitHub and
then tell people to download it from there. We then often get the question: "But
_how_ do you download something from GitHub?" Now this may seem like a silly question
to experienced users, but it is true you cannot just download
a file that you see listed in a repository. There is no Save or Download button and when you click on a file it is opened
in a browser and not downloaded. And if you right-click on a
file and save it you end up with a file containing HTML
code and not the content you expected.
Actually, you can download a file
if you open it in 'raw' mode first and then right-click to save it as a file but this is, of course, undoable
when there are many files. Now called 'Code' button! The thing is that there *is* an
easy download Code button, but you can only see it when you
are in the root of the repository. So, click the root of the repository to get there. Now it is easy. Just click the green
button labeled 'Code'. When you do that, you might get confused by the
surprising options about cloning with HTTPS or open it on your desktop or download ZIP, here you just click 'Download ZIP'
and ignore the other stuff.
You don't need to sign in
or have an account, just ignore that message. So, that's it? Well… that depends. The name of the file you
downloaded will end with '-master'. When you unpack it, you will get
a folder with the same name. Most of the time this doesn't really matter, but it does when the download happens to be an Arduino sketch. For the Arduino IDE the name
of the dot INO file ('.INO') must be the same as the name
of the folder that it is in. The solution is simple: remove te '-master' part by renaming the folder. Usually, you do not have to do this when the sketch
is inside a folder nested inside the ZIP file, because the nested folder will already have the same name as the '.INO' file.
If, on the other hand, the download is an Arduino library, then the Arduino IDE
knows how to deal with it. You can import it using the 'Add .ZIP library'
option from the Sketch -> Include library menu. Many projects on GitHub are
continuously evolving. If you download a ZIP file as we did before, you get what is called a
'development snapshot' and that may not work at all or it may not do what you expect from it.
For this reason, one tends to
publish stable versions that work and have been tested, and that are called 'releases'. These releases are often hosted on another website, for instance on the project's official website, but GitHub also offers space for them. Check the releases tab/button to see if there are any, and if there are, download the most recent one or
another version of the file you need.
You might also want to check the releases tab when you are not at all interested
in the source code of the project but only in a pre-compiled binary
to run on your platform. Finally you can use the official
GitHub method to download a project and that is by cloning a repository. To do so, you may first have to install
a Git client on your computer. There exists clients with nice
graphical user interfaces, and clients that you control
from the command line. In either case you will need the complete
URL of the repository you want to clone. You can get it from the
download Code button, again, but this time by copying the URL
in the Clone with HTTPS box. Click the copy button next to it to do this. In the command-line interface first navigateto the
folder where you want your clone of the repository, then type the command
'git clone' and paste the URL behind it,
and hit Enter. If all is well, the cloning process will start. In the desktop-interface,
from the menu, select 'File', 'Clone a repository', browse to the destination
folder and paste the URL you copied before in the box
labeled 'Repository URL', and then click 'Clone'.
So, that's it for now. I've shown you several ways to
download something from GitHub. There may be other ways but as I never needed them, you probably won't need them either. Most of the time just clicking the
green download Code button and save a ZIP file is enough. But, to do so, you must know
where that button is. And now you know, it is visible when
you are in the repository's root folder! Personally, I think cloning is
easier than downloading as you don't have to unpack anything and you can clone directly to
the folder where you want it, and you don't get the '-master' added
to the name of the repository. Okay, well, that's it. I hope you found it
useful and thank you for watching..