Using Git in Eclipse for CSSE230

In CSSE230, we will use a source control system called Git. Here is how to checkout and manage a repo using Eclipse's Git plugin.

Note: if you are off campus, it is recommended (for better stability, and to avoid a potential blockage from the firewall) to connect to the Rose VPN before performing these commands.

Set up your Eclipse workspace

Perform this step once at the beginning of the course (or whenever you want a fresh workspace to use.)
  1. Crete a new workspace. In Eclipse, open File > Switch Workspace > Other..., browse to where you want to place your new CSSE230 workspace, and hit Launch. You should now have an empty Package Explorer view.
  2. Open Eclipse's Git Repositories view. In Eclipse, select Window > Show View > Other. Type Git to filter the options, then open Git Repositories. You should now see a Git Repositories view with options like adding a new repository, cloning a repository, etc.

Clone a Repository

Perform this step the first time you interact with a repo (your individual CSSE230 repo, a team repo, etc.) Once the repo shows up in your Git Repositories view, you shouldn't need to do this step.
  1. In your Git Repositories view, select Clone a Git repository.
  2. Ignore the URI field for the moment, and fill out with the following: The URI field should have been auto-filling as you filled the other fields, and should now read
    ssh://USERNAME@gitter.csse.rose-hulman.edu/srv/repos/csse230-TERM-USERNAME
    with your username, of course. Hit Next.
  3. In branch selection make sure "master" is checked and click next.
  4. In Local Destination, Browse to where you want the repository cloned. You can configure anywhere you like (Eclipse may require you to use an empty directory) but I suggest putting it inside your Eclipse workspace directory. Click Finish.

Import a Project

Perform this step to check out a project (like WarmUpAndStretching) into your Eclipse workspace.
  1. In Eclipse, select File > Import..., then under Git select Projects from Git, and hit Next.
  2. In the Select Repository Source window, select Existing local repository (since you cloned it, the repo is already on your local machine!)
  3. In the Select a Git Repository window, select the relevant repo (your personal repo or a team repo), and hit Next.
  4. In the Select a wizard to use for importing projects window, leave it on Import existing Eclipse projects, make sure the working tree of your cloned repo is selected, and hit Next.
  5. In Import Projects, select the project/s you want to import (e.g., WarmUpAndStretching) and click Finish.
  6. You should see a folder for the project (e.g., WarmUpAndStretching) in your project browser.

Push

When you've made meaningful changes to a file, you'll want to add/commit it to your Git repo and push it to the remote server (so we can later grade it, and so teammates can pull your changes). Here's a sample workflow:

  1. In the Package Explorer, open (say) WarmUpAndStretching > src > anagram > Anagram.java. Make an edit: say, add a whitespace character, and save.
  2. In Package Explorer, you'll notice a > appear on any part of the project that has been changed since the last pull from master.
  3. Right click on one of these (say, the WarmUpAndStretching folder) and select Team > Commit...
  4. Verify that Anagram.java appears in your list of "Staged Changes".
  5. Add "test push" to the Commit Message.
  6. Select Commit and Push... [Note: Selecting Commit will commit your changes to your local repo, but won't push them to the remote version that we will eventually grade.]
  7. Note: if there are any files in the project that shouldn't ever be staged for commits (like a .gitignore file), you can right-click and choose "Ignore".
  8. Verify that the dialog reports "Pushed to - origin".
  9. If the push didn't work, you may need to first Pull any changes from the remote repo. See the next section.

Pull

Your instructor will periodically add/push new projects to your personal repo. When this happens, you will need to pull changes from the remote repo to bring yours up-to-date before pushing your own changes. You will also make use of pulling when working with other students on a team.

  1. Right-click on the repo in the Git Repositories window, and select Pull...
  2. Verify you are pulling from the remote repo on the gitter server, with Reference: master. You likely want to Merge when pulling (unless you want to do more sever actions like undoing local changes.) Click Finish.
  3. As long as there weren't any major merge conflicts, this should go smoothly. You should get the updated files.
  4. You can also pull changes for a project (like when working on a team): right-click it in the Package Explorer view and select Team > Pull..., then follow similar steps to the above.

Confirm

Students often like to confirm that their work has been pushed to the git server. You can do that easily following these instructions.

Good Advice for Minimal Merge Conflicts