Using git for Homework due Wed 29 Aug 09:00

In this assignment you will:
\item Establish...
...s for working with {\tt git} from the command-line

Preparation for Lab Day

Read and follow the instructions in the first three sections of Using git for Homework. The sections you should work through are titled: ``Background'', ``Setting up Your Workspace'', and ``Setting Up a Hosted Repository''. The URL for the base homework repository for this course is:

For this lab day you will be required to do work on the computers in the lab so take time to log in on the day before the lab begins to make sure you remember your credentials because we will not have time in class to troubleshoot login issues.

To summarize, when you come to class for lab day you should:

Lab Day

  1. When you arrive to class, log in to one of the lab computers. All remaining steps should be done from a lab computer.

  2. Open a terminal window and create a clone of your homework repository:

    git clone

  3. Change directory to the newly created p2_homework directory: cd p2_homework

  4. In order to remain consistent in our naming, let's go ahead and rename this remote to ``mine'' using: git remote rename origin mine

  5. Use: git remote -v to verify the rename worked.

  6. Change directory to the hw01 directory: cd hw01

  7. Edit the file (you can use gedit or jgrasp or vim). In the comment block at the top enter your name as author and the current date as version. Then compile and run the program as it is. Enter a new movie and then list all movies to verify it was entered correctly.

  8. Switch to the data directory (cd ../data) and then make a copy of the data file (movielist.txt) and name it tinymovielist.txt: cp movielist.txt tinymovielist.txt

  9. Edit the new tinymovielist.txt file (you can use gedit or jgrasp or vim) so that most of the movies are deleted leaving only about 10 movies. Save the file.

  10. Switch back to the hw01 directory (cd ../hw01) and edit the Java source code again and modify the String constant named DATAFILE so it refers to the new tinymovielist.txt file.

  11. Back at the command line enter the command: git status

    Take time to observe the output. This command will be used often to determine what has changed since the last commit. In this case it should indicate that you have modified a file and created a new file and that both of those actions are ``unstaged'' ... which means you haven't indicated that you want these changes to be remembered.

  12. We need to tell git that we want our changed to be included in the next commit so you will add them to your staging area with these commands: git add and git add ../data/tinymovielist.txt. Now issue the git status command again and compare the output with the previous result. It should show these changes as having been staged.

  13. Now we are ready to commit. With each commit you will attach a message indicating the changes you are committing. Use this command: git commit -m "Created Small Datafile for Testing Purposes"

  14. Issue git status again and verify that there are no uncommitted changes. If you use git log you should see there are now two commits.

  15. Edit the Java source code and add a new method called searchByYear that accepts the three arrays as parameters along with the number of elements in the arrays. It will not return any values. Leave the body of the method blank except for a single print statement that gives a message ``Search by Year''. Do, however create a comment that conforms to JavaDoc requirements. As part of your homework assignment you will actually complete this method. For documentation purposes you need to know what this function will do: prompt the user to enter a year and display all movies that match the given year.

    NOTE: A method that has a defined header but that does nothing is called a ``stub'' method.

  16. If you look at the method called menuChoice you can see that the user is prompted to enter a value of 6 to select the ``Search By Year'' action. In main() (inside the while loop) add an if-statement that will call the mostly empty searchByYear method in the event the user entered a at the menu. Compile, test, and tweak as necessary to get the changes you made to work. When the user enters 6 at the menu they should see the output of the single print statement in the new searchByYear method.

  17. It is time to commit your changes. Remember the sequence:
    1. git status (to see what has changed)
    2. git add xxxx (as necessary to stage changed/new files to be committed)
    3. git status (to verify everything you want to commit is in the staging area)
    4. git commit -m "Explanatory Message" (to commit the changes)
    5. git status (to verify everything committed as you expected)

  18. We are done making changes to this source code for lab day so let's go ahead and push our most recent changes to BitBucket: git push mine

    When you are prompted to enter a password you will enter your BitBucket password. If successful, your BitBucket repository will reflect all of the changes you just made. So, when you are ready to work on your homework you will begin by pulling the changes from BitBucket into whatever environment you plan to use for working on homework. NOTE: MAKE SURE YOU FINISH THIS STEP!

  19. If you finish early, take time to begin reading the homework assignment. For that assignment you will be need to do your work in whatever environment you set up in the prelab for doing homework.


This lab day is quite a bit different than most will be. In particular the instructions were especially prescriptive. In the future the instructions will not include specific commands to type. The purpose of this lab day was to walk you through the process of working with a VCS. Feel free to refer back to these steps if you don't remember a specific git command.

Quick Links