CS 240 Homework 1 - Getting Set Up and Introducting Git
Due Thu Sep 11 at 11:59pm
Overview
The purpose of this assignments to get you set up for the course, and get started with git and GitHub. Git is a version control system (used to organize source code when multiple people are working on it), and GitHub is a hosting service for organizing git-controlled projects.
This assignment will walk you through setting up git and GitHub for use in this course, give you a chance to use an online tutorial (you'll probably do that a lot in this course), and give you some practice making and submitting changes to a repository.
Assignment Objectives
- Get setup with the Bookware VM, git, and GitHub
- Learn the basics of using git
- Be able check out and submit changes to a git repository
- Evaluate an online programming tutorial
Assignment Details
There are lots of pieces to this assignment (as you need to get setup with everything), but all of them should be straightforward. These will take some time--do not leave this until the last minute!
1. Setup the Bookware VM
The first thing you'll want to do is get a development environment setup for this course. Luckily, the textbook comes with a virtual machine image that contains all of the tools referenced in the text that we will use in the class. See section A.3 in the text for further details.
- Detailed instructions on getting and using the Virtual Machine (VM) can be found on the textbook's website, with further details in the textbook. Note that the VM image is ~2GB in size, so make sure you have time to download it! (You can also get started on the next pieces of the assignment while it is downloading...) The VM image should already be located on lab computers.
- You are welcome to install your own copies of the tools (git, ruby, rails, etc), but note that the textbook examples assume very specific versions of each component. I recommend using the VM until you're comfortable enough with the tools to diagnose the source of any problems.
- Although the book doesn't suggest it, you may want to install a coding text editor--I like (and will be demoing with) Sublime Text but you can use whatever you want. Note specifying Sublime as a command-line editor (e.g., for mac) is good too
- Note that this assignment (and this class) in general will require you to work with the command line interface (CLI). If you're not familiar with the bash command line or need a refresher, you might check out these videos
2. Configure Git and GitHub
The next thing you'll need to do is configure git and sign up for GitHub. More details can be found in section A.7 of the text.
-
Sign up for a GitHub account at
https://github.com/join
- You should register a username that is similar to your UPS username and identifiable as you:
'myusername-ups'
or similar would be ideal. This will make it easier for us to collaborate and for the professor to figure out who submitted what, rather than needing to figure out who 'LeetCoder2014' is.
If you already have a user account on github (whose username is not immediately identifiable as you), you can register a separate one just for the purposes of this class. - You should register a username that is similar to your UPS username and identifiable as you:
-
Once you've registered an account, send the professor
an email
letting him know what your username is. That way he can add you to our GitHib organization and give you access to the repositories.
- Please be patient, as your professor is a busy man and needs to add people (mostly) manually.
-
Once you are part of the
UPS-CS240-F14 Organization,
you will have access to a few differnet repositories. These will include the class Hwk1 repository for this assignment, as well as a personal repository for your future homework assignments. This repo should be located in the UPS-CS240-F14 organization and called
hwk-<ups login here>
.- You'll set up your dev environment to allow you to submit your homework answers at the end of this assignment (section 5)
-
Configure git so that it knows who you are, so that in a multi-person project each commit is tied to a specific person. In the console (with git installed), run the following commands:
git config --global user.name "YOUR NAME HERE" git config --global user.email "YOUR UPS EMAIL HERE"
- You'll also want to set up an SSH key to allow you to push and pull over SSH (the Secure Shell protocol--this allows you to connect to GitHub securely). Again, see section A.7 for more details. You may also want to cache your github password so you don't have to enter it repeatedly.
- You can also setup git to use a graphical text edit (like Sublime) for writing commit messages using
git config --global core.editor <command>
3. Git Tutorials
At this point, you should be all set up to use git! But how exactly do you use this thing?
While we'll be going over the basics in class, another good way of learning a new programming language or tool is to take advantage of the many online tutorials and guides.
There are numerous tutorials for git available; for this assignment, you will be using and evaluating one of the online, interactive versions:
- If your last name begins with the letters A-E, Gitimmersion (labs 1-35)
- If your last name begins with the letters F-M, Learn Git Branching (all "main" tutorials)
- If your last name begins with the letters N-Z, tryGit (challenges 1-25)
You are welcome and encouraged to look at the other tutorials--particularly if your assigned tutorial isn't helpful for you. But you still need to complete your assigned tutorial so you can evaluate it!.
-
There are lots of other guides and resources out there as well. A couple of recommended ones:
- http://betterexplained.com/articles/a-visual-guide-to-version-control/ Note: This is a GREAT read for understanding version control in general! Be sure and read the followup article on Distributed Version Control
- http://git-scm.com/book/en/Git-Basics
- http://rogerdudler.github.io/git-guide/
4. Committing a Change
Now that you know how to use Git (right?), let's do something with it. For this part of the assignment, you will clone an existing repository, modify some files, and then push out your changes.
-
Start by cloning the
hwk1
repository (Note: all instructions in this assignment describe cloning via HTTPS. You are welcome to clone via SSH instead; generally you replace 'https://github.com/' with 'git@github.com:')git clone https://github.com/UPS-CS240-F14/hwk1
- In the VM, you should probably do this in the "Documents" folder
-
Switch into the hwk1 directory
cd hwk1
-
Create and switch to a new branch to do "development" on
git checkout -b develop
It may feel a little silly to make a separate branch for the small number of changes we're making, but it's good practice! -
Modify the
class_list.txt
file to include your name and information about yourself, following the format (if there are any questions, post them to Piazza!) -
You may want to backup your changes at this point by committing them
git add class_list.txt git commit -m "<a descriptive message of your commit>"
- Remember: commit messages should summarize what the commit does to the repo in less than 50 characters (you can add more detail on the following line). Use the imperative tense: "adds Joel's name to the list"
-
Modify the
tutorials.md
file to add a review of the git tutorial you completed. This does not need to be extensive, but should include at least one thing that "works" about the tutorial and one thing that doesn't. You should also look through other people's comments, and expand onto them if you can. Our goal is to make a nice summary of these tutorials that may be helpful to others (e.g., future CS 240 students)!- This is the most involved part of this assignment.
- Yes, using a Wiki might be more effective at achieving this goal, but we're learning git.
- Similarly, you should make these changes using the command-line interface, rather than simply editing through GitHub.
- Note that this file is formatted using Markdown
- Commit your changes to your local repository (see above)
-
Merge your development branch back into your master branch. First checkout the master, then perform the merge.
git checkout master git merge develop
-
Before you push your changes back out to the rest of the repositoryFinally, you should push your changes back out to the rest of the repository. First, make sure to pull in anything that has changed since you began editing
git pull
and finally push the changesgit push
- If you get any merge conflicts througout this process, you'll need to resolve them!
And that does it for this part of the assignment!
5. The Homework Repository
There is one last task to do for this assignment, and that is to get your system setup to turn in future assignments. Assignments will be turned in by uploading files to your own personal homework repository (that has been automatically set up for you). However, we have to do a little bit of work so that you can pull starter code from the group homework repo, but submit to your personal repo.
-
First, clone the current homework repository, and then
cd
into it.git clone https://github.com/UPS-CS240-F14/homework.git cd homework
-
Now we're going to change that local copy so it instead points at your personal repository. By default the remote called
origin
is set to the location that you cloned the repository from. You should see the following$ git remote -v origin https://github.com/UPS-CS240-F14/homework.git (fetch) origin https://github.com/UPS-CS240-F14/homework.git (push)
We don't want that remote to be the origin, instead, we want to change it to point to your repository. To do that, issue the following commandgit remote rename origin upstream
This changes the name of the remote from "origin" to "upstream". Now you should see the following$ git remote -v upstream https://github.com/UPS-CS240-F14/homework.git (fetch) upstream https://github.com/UPS-CS240-F14/homework.git (push)
-
Now we just need to give the repository a new
origin
---namely, your personal homework repo!git remote add origin https://github.com/UPS-CS240-F14/hwk-<ups login here>.git
Remember to substitute in your UPS id!
Once it's set up, it should look something like
$ git remote -v origin https://github.com/UPS-CS240-F14/hwk-<ups login here>.git (fetch) origin https://github.com/UPS-CS240-F14/hwk-<ups login here>.git (push) upstream https://github.com/UPS-CS240-F14/homework.git (fetch) upstream https://github.com/UPS-CS240-F14/homework.git (push)
-
Test out your setup by pushing your local repository out to your personal repository on GitHub
git push -u origin master
You should see something like:Counting objects: 7, done. Delta compression using up to 8 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (7/7), 1005 bytes | 0 bytes/s, done. Total 7 (delta 0), reused 0 (delta 0) To https://github.com/UPS-CS240-F14/hwk-jross.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
Note you only needed to specify the remote when pushing once (to setup remote tracking branches). In the future, you can just push$ git push Everything up-to-date
Now you're all setup! Using the homework repositories is pretty simple.
-
You can get the latest starter code by pulling from the master branch of the 'upstream' remote
git pull upstream master
(You can also be more explicit andfetch
thenmerge
, such as if you have a current working branch)git fetch upstream git merge upstream/master
- You work on your homework directly in this repository, using branches and committing changes as appropriate (e.g., when you complete part of an assignment).
-
Finally, once you've finished an assignment and committed your code to your local repository, you can push the code back out to the GitHub copy of your repository
git push
The push is sort of like the "submission"; you can check that everything is up to date by browsing the repository on GitHub
Submitting
Successfully committing and pushing the required changes to the hwk1
repo and your personal homework repo on GitHub counts as a submission of this assignment. Remember to push
your changes to GitHub!
Grading
This assignment will be graded out of 10 points:
- [2pt] You have signed up for GitHub and joined the organization
- [2pt] You have added your name to the
class_list.txt
file and pushed the change to GitHub - [5pt] You have added to the review of your assigned tutorial
- [1pt] You have pushed a copy of the
homework
repo's starter code to your personal homework repo