Eric Bezzam · Follow
--
This post is a part of a (planned) series on “Collaborative Coding with GitHub”, a workshop that I’ve given several times at EPFL (through LauzHack) to help students and researchers familiarize themselves with Git and GitHub. The posts are meant to complement the workshop, whose material (slides and recording) can be found here. However, the posts can also be used as a standalone guide. Enjoy!
In this post, we’ll show four ways of downloading a GitHub repo to your computer:
- Downloading a zip file from GitHub.
- With GitHub Desktop.
- Though VS Code (preferred)
- From the command line.
We’ll be working with the repo we made in a previous post, or you can try the steps below with any other public repo on GitHub. Having different ways of downloading a repo is useful because depending on your situation, one approach may not be possible. Let’s get started!
From the repo’s homepage on GitHub, click on the green “Code” button, and then “Download ZIP”.
Unzip the file, and there you have have all the files from the main
branch!
You can now open the folder/files in your favorite editor and start coding. Keep in mind that with this method, you won’t be able to share your changes with others, or get changes from others through the git
protocol. For that, you’ll need to use one of the other methods.
GitHub Desktop is an application that provides a graphical interface for working with GitHub repos. It’s available for Windows and Mac, and you can download it here. (For installation on Ubuntu, see here.)
After downloading and installing GitHub Desktop, open the application. It will most likely ask you to log in:
Go ahead and do that and authorize GitHub Desktop to access your GitHub account.
From GitHub Desktop, you can “clone” (which is git
terminology for “download”) a repo by navigating to the “File” menu and selecting “Clone repository…”.
Search for your repo that you want to clone, and select it. You can also choose where to save the repo on your computer. Then click “Clone”.
If you would like to clone someone else’s repo, go to the URL tab, and enter the URL or username/repo-name
of the repo you want to clone. Then click “Clone”.
After everything has downloaded, you should see the repo in GitHub Desktop!
There’s nothing too interesting here as the repo is new. If you press the “History” tab, we can see all the files that were created when we initialized the repo through GitHub’s interface.
In the next post, we’ll see how to make changes to the files and synchronize them with GitHub (only second part can be done with GitHub Desktop).
Note that you can also download from GitHub Desktop by clicking on the green “Code” button on the repo’s homepage on GitHub, and then “Open with GitHub Desktop”.
If you’re using VS Code, you can also clone a repo through the desktop application. VS Code is one of many IDEs (Integrated Development Environments) that you can use to write code and that has built-in support for git
. It’s a personal preference (that I will further explain in a future Python development series), which is why I present it here as an option.
Open a new window of VS code and press the “Source Control” icon on the left-hand side, and then the “Clone Repository” button.
A dropdown menu will appear at the top, where you can enter the URL of the repo you want to clone. You can also choose where to save the repo on your computer. Then click “Clone”.
“Clone from URL” will let you download a repo from GitHub, or any other website that uses the git
protocol. “Clone from GitHub” will let you download a repo from GitHub, but you’ll need to be logged in to your GitHub account. I recommend the second option if you’re cloning a private repo, otherwise you’ll have to create a secret-public key pair and add it to your GitHub account (as described here).
After VS Code has identified which repo you would like to clone, you’ll be asked to pick a folder to save the repo in. Once you do that, VS Code will download the repo and ask if you want to open it.
Go ahead and click “Open”. You may be asked if you trust the authors. If so (which I think you can if it’s your repo!), go ahead and click “Yes”.
And there you have it! You can now see the files in your repo in the “Explorer” tab on the left-hand side.
You’ll notice that VS code renamed the folder to my-school-project-1
because it detected that there was already a folder with that name (as I downloaded it to the same folder as I did with GitHub Desktop).
The reason I prefer this approach for cloning repos, is that we can use the same software for editing code and for managing the repo (from the “Source control” icon). From GitHub Desktop, you cannot edit files.
In the next post, we’ll see how to use VS Code to make changes to the repo and synchronize them with GitHub.
Finally, you can also clone a repo from the command line. This is useful if you’re working on a server, or if you don’t have a graphical interface (or if you’re just one of those cool people who likes to do everything from the command line!)
Before proceeding with this method, there are two things you’ll need to do:
- Have
git
installed on your computer. You can check if you have it installed by typinggit — version
in your terminal. If you don’t have it installed, you can download it here (and some instructions for different OS here). - Have an SSH key set up with your GitHub account (as described here). This is necessary if you want to clone a private repo. This is not necessary for a public repo (you can clone it with HTTPS), but it is necessary for a private repo. However, in any case (private or public repo) it is good practice to use SSH.
With all that (one-time) setup done, we can finally clone! Go to the repo’s homepage on GitHub, and click on the green “Code” button. Then click on the clipboard icon to copy the URL for SSH cloning.
Then open a terminal and navigate to the folder where you want to save the repo. Then type git clone <URL>
, where <URL>
is the URL you copied from GitHub. For example, for the repo we created in the previous post, we would type:
git clone git@github.com:ebezzam/my-school-project.git
Go into the folder that was created, and you’ll see all the files from the repo!
cd my-school-project
ls -a # -a flag shows hidden files that begin with "."
Again this approach is useful if you’re working on a server, or if you don’t have a graphical interface. However, as VS Code allows remote development, you can also use VS Code to manage a repo and edit files on a server. We’ll see how to do that in another post.
In the next post, we’ll see how to make changes to the repo and synchronize them with GitHub from the command line.
In this post, we saw four ways of downloading a GitHub repo to your computer. Depending on your situation, you may prefer one over the other. In the next post, we’ll see how to make changes to the repo and synchronize them with GitHub.