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.)
- 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.
- 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.
- In your Git Repositories view, select Clone a Git repository.
- Ignore the URI field for the moment, and fill out with the following:
- Host:
gitter.csse.rose-hulman.edu
- Repository path:
/srv/repos/csse230-TERM-USERNAME
,
where TERM
is the 6-digit Banner code for the
term, e.g. 202040
for Summer 2020, 202110
for Fall 2020, 202120
for Winter 2020-21, etc.
and
USERNAME
is your Rose-Hulman username.
- Connection protocol: ssh
- User: your RHIT username
- Password: your RHIT password
- You can select Store in Secure Store to avoid having to enter credentials frequently.
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.
- In branch selection make sure "master" is checked and click next.
- 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.
- In Eclipse, select File > Import..., then under Git select Projects from Git, and hit Next.
- In the Select Repository Source window, select Existing local repository (since you cloned it, the repo is
already on your local machine!)
- In the Select a Git Repository window, select the relevant repo (your personal repo or a team repo), and hit
Next.
- 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.
- In Import Projects, select the project/s you want to import (e.g., WarmUpAndStretching) and click Finish.
- 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:
- In the Package Explorer, open (say) WarmUpAndStretching > src > anagram > Anagram.java. Make an edit:
say, add a whitespace character, and save.
- In Package Explorer, you'll notice a > appear on any part of the project that has been changed since the last
pull from master.
- Right click on one of these (say, the WarmUpAndStretching folder) and select Team > Commit...
- Verify that Anagram.java appears in your list of "Staged Changes".
- Add "test push" to the Commit Message.
- 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.]
- 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".
- Verify that the dialog reports "Pushed to - origin".
- 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.
- Right-click on the repo in the Git Repositories window, and select Pull...
- 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.
- As long as there weren't any major merge conflicts, this should go smoothly. You should get the updated files.
- 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
- This is for future reference, when working on a team.
- Pair program whenever possible.
- Use descriptive commit messages.
- Always do a Team > Pull before you begin programming.
- Always to a Team > Commit and Push when you finish.
- If you do have to resolve a merge conflict, remember you must accommodate both changes.