Objective

Learn how to fetch an assignment from Github and upload your changes!

Task

  1. Import this assignment repository into Eclipse
  2. Make a change in the source file, save the file
  3. Upload your changes to Github
  4. Confirm your changes have been uploaded on Github by visiting your repository. This confirms your assignment has been submitted. (https://github.com/WilcoxAPCS/introduction-to-github-yourusername)

Before you start

  • If your workspace already has a project called HelloWorld, the import will not complete properly due to namespace conflict! Either open your Eclipse in a new workspace upon startup, or right click on your HelloWorld project (not the Java file, the folder) and hit 'Delete'; the default option will remove the project from your Eclipse workspace, but not on the computer.

Table of Contents

Importing your Assignment into Eclipse

  1. Open Eclipse, File > Import

  1. For Select, Select Git > Project from Git > Next

  1. For Select Repository Source, Select Clone URI > Next

  1. For Source Git Repository, enter the following:
    • URI: https://github.com/WilcoxAPCS/introduction-to-github-username. This should autopopulate the Host and Repository path field. Remember to substitute your own username in!
    • Your username and password for Github in the Authentication section, then Next.

  1. For Branch Selection, master should automatically selected, then just hit Next.

  1. For Local Destination, a directory will be auto-populated for you, feel free to change this if you wish, otherwise Next.

  1. For Select a wizard to use for importing projects, make sure Import existing Eclipse projects is selected, then Next.

  1. On the Import Projects menu, you should see the HelloWorld Project. Make sure it is selected and you're done! Hit Finish

  1. You should now be able to see your new project in the Package Explorer. If you cannot see your Package Explorer. Window > Show View > Package Explorer.

Uploading your Changes to Github

  1. Right click on your project. Team > Commit

  1. The Git Staging panel will open. Move any changes you want to commit from Unstaged Changes to Staged Changes by selecting the item, and clicking the green plus.

  1. Once you have staged everything your heart desires, add a commit message (this usually describes what your changes do). For Author and Commiter, put username <email@email.com>, replacing with your username and email of course. Commit and Push!

  1. You will be prompted to log in, so Github knows who is making the changes. You should be able to see your changes on your page after this!

Understanding GitHub

For class, you can simply follow the instructions above to import and submit your assignments. This section is additional reading for those interested in developing a deeper understanding of Git and the terminology used in the above sections.

What is Git?

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. The terminology you have seen in the instructions above (i.e. repository, branch, remote, commit, staged, push) is Git terminology. Version control allows us to easily maintain versions of our code, and collaborate with others.

What is GitHub?

GitHub is a website where you can upload a copy of your Git repository. It is a Git repository hosting service, which offers all of the distributed revision control and source code management functionality of Git as well as adding its own features. GitHub Classrooms, which is what we are using is one of GitHub's additional features. It is also a standard platform to show off your coding projects!

How does it work?

We will use this coding assignment as an example.

When you accepted the assignment, a private GitHub private remote repository was created for you, hosted on GitHub. Using Eclipse as an interface, we fetched a local copy of the repository from the host.

This local Git repository will track your changes, allow you to make commits, and push to the back to the remote repo (the version seen on Github)

Terminology Description
Working Directory The directory in which you are currently working (i.e. What you are seeing in Eclipse as right now).
Staging Area A place to put all the files you want to commit
Local Repo Your local version of the repository.
Remote Repo The hosted version of the Repository

Note: In the use case of a private repository where you're working alone, it might not be immediately obvious why we have both a local and a remote repo. Why not commit straight to remote? This is because in real life scenarios, there are many cases where you want your local repository changes to be approved before you push to the published remote repo. Another feature often used is branches, which we will not cover as we will simply use the master branch, but more information about branches can be found here.

In Eclipse, when we used the green plus to move Unstaged Changes to Stage changes, it is using the add function to move our changes from our working directory to our staging area. Then when 'Commit and Push' was pressed, the commit command was used to push changes from our staging area changes to our local repository immediately followed by a push command to push our local repository changes to our remote (so we can view our changes on GitHub!).

The functionality of Git is incredibly rich, and there is much more to learn beyond what is covered here. A list of additional functionality is available on this page, for those looking to learn more.