Algorithms and OOD (CSC 207 2013F) : Labs
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Summary: In this laboratory, you will practice using Git. Although you can use the command line (see commands below) to manage your GitHub repositories, we will try communicating with GitHub directly from Eclipse, using the EGit plugin. After all, if we're using an IDE, we should integrate everything, including our source code management system.
If you do though opt to go the command line route in the future, you can find a list of useful commands at the end of this lab.
a. Make sure you have read the Introduction to Git reading.
b. Make sure that you have done the Introduction to Eclipse lab
c. Log in and open a terminal window.
d. Start Eclipse.
Create a GitHub account at https://github.com/
As you may recall, your life is easier if you do a bit of configuration before working with Git. You'll find it useful to configure in both the terminal and Eclipse. We'll start by working in the terminal.
First, open a new terminal window.
Next, type these commands.
$
git config --global user.name "YourName"
$
git config --global user.email username@grinnell.edu
Finally, set your editor.
$
git config --global core.editor editor
You can use emacs
, vi
(or vim
,
or vim.basic
), or even gedit
.
EGit may not be installed on your workstation, so you get to configure Eclipse to use EGit.
a. From the
menu, select .b. In the dialog box that pops up, click
.
c. In the next dialog box that pops up, use "EGit" as the name and
http://download.eclipse.org/egit/updates
as the location.
d. You should then see Eclipse Git Team Provider and JGit in the middle pane. Select them both.
e. Click the
button.f. You'll probably get an error message and a longer list of items. Uncheck Task focused interface for Eclipse Git Team Provider (thanks to StackOverflow for helping me figure this out).
g. Click the
button.h. Eclipse will ask you to review the items to be installed. Click the
button.i. Review the user license.
j. Click the
button.k. After the software installs, you will probably need to restart Eclipse.
Create a folder on your computer where you will store your GitHub
repositories. For example, you might name it CSC207
.
Go into Eclipse
> . A preferences window should open. Click the triangle next to . Then, click on . Change the default repository to the one you just created and click .You should still be in the preferences window. If not, reopen it. Then click the triangle next to user it says something like the following.
to expand that item. Click on and make sure that underemail youremail@grinnell.edu name Your Name
If it doesn't you should add new entries for both those values. Click on user.name” as the Key and your username on GitHub as the Value. Click on again and enter “user.email” as the Key and the email you used for GitHub as the Value.
and enter “To help identify yourself, you will need a pair of RSA keys.
Once again, open the Preferences window if it's not already open.
a. In Eclipse, expand the
preference. Then expand . Select Click the then . Copy the public key to your clipboard. Enter a passphrase. Click to save your private key and click . Exit the preferences.b. Now we have to tell GitHub about the key. Log in to your account on the GitHub Web site. Go to the your
(which may appear as a pair of tools). Under click . Give it a descriptive name (EGit), and paste the public key you just copied from Eclipse.a. Log in to your GitHub account.
b. Somewhere on the page (along the right hand column, at the time of this writing, but it changes), there should be a button labeled
(although that name changes, too). Click that button. A dialog should appear.
c. Name your repository (e.g., git-exercise
). Click
the buttons to make it public and to initialize the repository
with a README file. Choose the Java .gitignore file. Choose
a license you like. Finally, click Create Repository
.
d. Copy the SSH link associated with your repository. You will need to look for the Clone URL button (currently along the right-hand side of the page), click on
, and then click on .The link should look something like the following:
git@github.com:username/sample-java.git
Warning! These steps are long, tedious, and exacting. However, they will become second nature after awhile.
Switch back to Eclipse.
You an now add, delete, and modify files as you please. The next challenge will be committing and pushing them back to the main repository.
Making our repository an Eclipse project introduced some changes.
For example, there's now a hidden .project
file and
the .gitignore
file has expanded a bit. We should
commit these changes to the repository.
Right click on your new project in the Package Explorer.
Select .gitignore
, .classpath
, and
.project
), enter a message (e.g., “Add Eclipse
project files”) and click .
This commit remains local. To get it to the main repository, we right click on the project and then select
> .Why do this now? So that we can distinguish these changes from our own.
In the Eclipse lab, you created a simple “Hello World” Java program. Create a similar program in your new repository. That is,
a. Create a new package, such as edu.grinnell.csc207.username.hello
.
b. Create a new class, such as HelloWorld
.
c. Add a main
method to the class that has the following
form.
public static void main(String[] args) { System.out.println("Hello, GitHub!"); } // main(String[])
d. Run your program to make sure that it's correct.
e. Save your program.
We've updated the repository and so should commit the code to the repository. We'll also push it back to the main repository. But instead of the two-step process, try using the
button.Note that we usually don't push immediately immediately after each commit, but it's handy to do so now. Normally, we do a series of small commits and only push once we've reached a larger goal.
Go to GitHub and see if the changes you have made are visible. You may need to navigate a few layers deep, since Eclipse makes a directory for each portion of the package.
Although we normally update code in our local copy of the repository, it is also possible to update code directly on GitHub. Navigate to the Java code you just wrote and click the
button.Change the output. Then scroll to the bottom of the page, enter a commit message, and click
.Our primary repository is now updated. How about our local repository? Let's see. Switch back to Eclipse. Open the Java code you created and edited. Has it changed?
It is unlikely that the Java code changed. Why? Because you haven't told Eclipse to pull the updated version. That's a two step process.
First, right click on the project and select
> . Next, right click on the project and select > . Cross your fingers that everything worked.On GitHub, update the Java file by adding another print statement.
In Eclipse, update the Java file by changing the output.
Determine what happens when you try to fetch and merge.
Find out what Eclipse does if you modify one of the files in the Git repository using Emacs or an editor of your choice.
You'll need to do this exercise with a partner.
Create a fork of your partner's repository.
Figure out how to copy your fork into Eclipse.
You'll need to do this exercise with a partner.
First, figure out how to give someone else administrative access to your repository.
Next, verify that they have administrative access by having them make a change and upload it to the repository.
Finally, figure out what happens if the two of you make changes.
git config --global user.name "Your Name" git config --global user.email your_email@example.com git config --global core.editor editor git help git clone git add git commit git pull git push
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013 Samuel A. Rebelsky.
This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.