• 4 hours
  • Easy

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 12/12/19

Clone a Repository, Bugs and all

Now that you've gotten a little tour, let's check out how to get a bit more hands on!

Create a Github account

Go back to the Github page and create your own account. You can do this by clicking on Sign up in the upper right-hand corner of the page. 

Github website
Github website

Go through the process of creating your account with a username, your email address and password that you would like to use.  You will have the option to create a free account with public repositories or a paid account that will give you the option of holding private repositories.

Check out and clone a buggy repository

Now that you are logged in, let's look at a repository that we will use to fix some code. 

Let's review the steps in depth below:

Explore the project

Right now, this repository contains some code. Under the  src  directory, I see a few Java classes so let's take a look at them.  There is something under the Issues tab. Let’s see what's going on there!

There are two issues.  Apparently somewhere in this code, there is infinite loop and we need to do some detective work to figure out why!  I also see that the second issue mentions a runtime error. I think we can use our debugging skills to figure out where that is happening! The first step to start working on fixes for the code is to clone the repository into Eclipse!

Clone the repository

Go to the right side of the page and click on the green Clone or download link and copy it by clicking the clipboard button.

                                       

Copy the HTTPs URL to clone the repository

Let’s take a look at Eclipse now and clone the repository. You may have to go to a window in the toolbar at the top and click Perspective -> New Perspective and then Other.  Scroll down the list to click on Git.

You should see an option like this in the Git Repositories view:

Git Repositories Tab
Git Repositories tab

You will also see the toolbar at the top with shortcuts to the same options:

Git Repositories Toolbar shortcuts
Git Repositories toolbar shortcuts

Click on Clone a Git repository and you should find the wizard below.  Where it says URl, paste the URL that you copied from the Github website for the repository. And it should autofill the contents at the top. Next, enter the username and password you created when you signed up for Github.com.

Clone the HelloBugs Repository
Clone the HelloBugs repository

Now click Next and it will ask you what branch.  Choose master and then click Next again.

                               

Configure the master and origin

You can select the directory, or file, that you want to use.  Leave the Remote name as origin and click Finish.

Add the repository as a project

Now that we've got our repository cloned, what do we do with it?  Let's check it out:

You will see that the project shows up in the Git Repositories tab with an arrow key and you can click on that to see the downloaded files.

                                           

Cloned repository in master branch in Git Repositories tab

Now you can see the cloned repository in the Git Repositories in Git form.  You've downloaded a copy of the repository on Github, and have therefore created a local repository.  This means that the repository is just on your machine.

How can you look at the code so you can fix it? Add the files from the cloned repository into the Project Explorer  so you can open it in the code editor. You can do so by following these steps:

  • Right-click in the Project Explorer and select Import

  • Choose Git->Projects from Git click Next

  • Select Existing local repository and click Next

Select the Cloned Repository
Select the cloned repository

For it to show in the Project Explorer, you have to add it as a New Project. 

Select  Import using the New Project wizard
Select Import using the New Project wizard

You can give it the same name and click Finish like in the wizard below.

Choose the same Name for the New Project
Choose the same name for the New Project

Now you should have the HelloBugs project in the master branch in your Project Explorer with HelloBugs.java.  Click on HelloBugs.java and it will show in your code editor.

The cloned HelloBugs project in the Git perspective in Eclipse
The cloned HelloBugs project in the Git perspective in Eclipse

Now you've successfully cloned a repository! In the next chapter, we are going to fix the bugs, commit them, and push them back into the repository on GitHub in a new branch!

Summary

Now you know how to:

  • Clone a repository from Github. 

  • Access the cloned repository in Eclipse. 

Example of certificate of achievement
Example of certificate of achievement