Using git for Homework due Wed 16 Jan 10:00

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

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: https://tsergeant@bitbucket.org/tsergeant/p2_homework.git

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

NOTE: I had originally planned for everyone to do the work today on the lab computers. There are more students than computers (and one of the computers is sick) so several folks will need to work on a laptop. I have a slight preference for you to use the lab computers because it will give you the ``opportunity'' to set up another local repository that is separate from where you did your pre-lab setup. The idea is that in a few steps you can set up a working environment just about anywhere! And then you can share information among those environments via your hosted repository in the cloud.

If You are Working on a Lab Computer

Follow the steps in this section if are working on a lab computer. If you are working on your laptop then skip to the next section.

  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 set up your git credentials with these commands:
    git config --global user.name "Your first and last name here"
    git config --global user.email "your-email@hsutx.edu"
    

  3. Create a clone of your homework repository:

    git clone https://yourbitbucketusername@bitbucket.org/yourbitbucketusername/p2_homework.git

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

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

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

  7. Change directory to the hw01 directory: cd hw01

  8. Edit the file ParallelArrayMovies.java (you can use gedit or jgrasp or vim or nano to edit files). 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.

  9. 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

  10. Edit the new tinymovielist.txt file so that most of the movies are deleted leaving only about 10 movies. Save the file.

  11. 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.

  12. 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.

  13. 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 ParallelArrayMovies.java 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.

  14. 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"

  15. 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.

  16. 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!

  17. Summary of git commands we use when we are ready to commit:
    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)
    6. git push mine (to upload the most recent version to your BitBucket account)

  18. Postscript: 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.

  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.

If You are Working on a Your Own Laptop

Follow the steps in this section if are working on your own laptop and you already have your working repository set up on it.

  1. Open the terminal window where you can issue git commands from the command-line.

  2. Verify that you no uncommitted changes: git status (should indicate that everything is up-to-date). If not then you'll need to commit the changes as follows:
    git add .
    git status
    git commit -m "meaningful message explaining what changes you are committing"
    

  3. Make sure you have the most recent versions of the base and hosted repositories:
    git pull origin
    git pull mine
    

  4. Edit the file ParallelArrayMovies.java that is found in the hw01 directory (you can use jgrasp or whatever other editor you normally use when writing Java programs). 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.

  5. Use the command-line to do this step. Switch to the data directory of your repository: (cd p2_homework/data) and then make a copy of the data file (movielist.txt) and name it tinymovielist.txt: cp movielist.txt tinymovielist.txt

  6. Edit the new tinymovielist.txt file (use any available text editor) so that most of the movies are deleted leaving only about 10 movies. Save the file.

  7. Continuing editing your Java source file and modify the String constant named DATAFILE so it refers to the new tinymovielist.txt file.

  8. 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.

  9. 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 ParallelArrayMovies.java 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.

  10. 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"

  11. 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.

  12. 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!

  13. Summary of git commands we use when we are ready to commit:
    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)
    6. git push mine (to upload the most recent version to your BitBucket account)

  14. Postscript: 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.

  15. 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.

Quick Links