Functional Problem Solving (CSC 151 2014S) : Assignments
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Setup] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2010S)] [Rebelsky (2013F)] [Weinman (2012F)] [Weinman (2014S)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)]
Due: 10:30 p.m., Wednesday, 2 April 2014.
Summary: In this laboratory, you will be practicing using Git. As you start, you will use the command line to manage your git repositories. (In the future, you may find it more useful to download one of the graphical user interfaces for Git.)
Note: This assignment is written in laboratory form. You will do most of the work and then answer a few questions using a Google form, available at http://bit.ly/151githw.
Collaboration: You may work alone or in a group of up to size four. Each student must create his/her/zir own account on GitHub (exercises 1 and 2). However, each group need only create one repository (remaining exercises). If you create only one repository, you should try to find a way to give everyone access to that repository.
Submitting: Please submit this assignment by filling out the form at http://bit.ly/151githw.
In case you've forgotten what you learned in the reading, there is a list of useful commands at the end of this lab.
a. Make sure you’ve read the Introduction to Git reading.
b. Log in to a MathLAN workstation and open a terminal window.
c. Create a directory to use for this assignment. I'd suggest something like
/home/username/Desktop/Git.
$mkdir /home/username/Desktop/Git
If you haven't already done so, create a GitHub account at https://github.com/
As you may recall, your life is easier if you do a bit of configuration before working with Git. If you haven't already done so, configure your account (name, email, editor).
First, open a new terminal window.
Next, type these commands.
$git config --global user.name "YourName"$git config --global user.email username@grinnell.edu
Finally, set your editor.
$git config --global core.editor gedit
I've suggested gedit as your editor because it is a simple,
GUI-based editor. We have a host of other editors in MathLAN, so you
could also use emacs or vim, for example.
a. Log in to your GitHub account.
b. Somewhere on the page (along the right hand column, at the time of this writing, but it changes), there should be a button labeled (although that name changes, too). Click that button. A dialog should appear.
c. Name your repository (e.g., git-example). Write a
short description. Click the buttons to make it public and to
initialize the repository with a README file. Choose a license you
like (or do without a license). Finally, click .
The easiest way to clone a repository is by using the HTTPS address of your repository. Get that address from the GitHub page (either from the address bar or from HTTPS Clone URL widget).
a. Open a terminal window and cd to the directory you created in the preliminaries. For example,
$cd /home/username/Desktop/Git
b. Once you are in that directory, use git clone to copy
the repository you created. For example, you might write
$git clone https://github.com/username/git-example
c. Verify that the repository contains the files that you expected.
You will likely find it easiest to use the file browser. You can
also type ls directory.
$ls git-example
We'll be using Git to store your files for this class, most of which will be created in DrRacket. So our first real work is to create a file and put it into our repository.
a. Create the program utils.rkt with the following
contents.
#lang racket
(require gigls/unsafe)
;;; Procedure:
;;; nums
;;; Parameters:
;;; n, a positive integer
;;; Purpose:
;;; Create a list of the integers [1 ... n].
;;; Produces:
;;; list-of-nums, a list of integers
;;; Preconditions:
;;; [No additional]
;;; Postconditions:
;;; (length list-of-nums) == n
;;; (list-ref list-of-nums i) = i+1
;;; for all i, 0 <= i < n.
(define nums
(lambda (n)
(cdr (iota (+ n 1)))))
b. In the terminal, switch directories to your Git repository.
$cd /home/username/Desktop/Git/git-example
c. Use git add to add the file to the repository.
d. Use git commit to commit this file.
e. Use git push to send the file back to GitHub.
f. Look at the repository on GitHub and verify that you've managed to get a file there.
We've told you that Git keeps track of your changes. So let's make some changes.
a. In DrRacket, change “nums” to the more
verbose “first-n-numbers”.
b. In the terminal, commit this change using the following command.
$cd /home/username/Desktop/Git/git-example$git commit utils.rkt -m "Change name of nums."
c. Make a list of the changes to the file with git log utils.rkt.
d. Get a visual description of the changes to the file with
git diff utils.rkt.
e. Push your changes back to GitHub.
f. Confirm that GitHub now contains the changed file.
Although we normally update code in our local copy of the repository, it is also possible to update code directly on GitHub.
a. Navigate to the code you just wrote and click the button.
b. Add an introductory comment, such as the following.
;;; File: ;;; utils.rkt ;;; Author: ;;; Your Name Here ;;; Summary: ;;; A few sample utilities, created as part of a lab on GitHub.
c. Scroll to the bottom of the page, enter a commit message, and click .
a. Our primary repository is now updated. How about our local repository?
Let's see. Switch back to the terminal window. Open utils.rkt
in DrRacket.
It is unlikely that the code changed. Why? Because you haven't told Git to pull the updated version.
b. Tell Git to grab the changes from GitHub using git pull.
c. Verify that you have an updated copy of the file: Quit and reopen DrRacket and open the file.
a. Make another clone of your repository on your Desktop.
$cd /home/username/Desktop$git clone https://github.com/username/git-example
b. You should now have two copies of utils.rkt, one in your
original repository and one in your new repository. Open both in DrRacket.
c. In the original version, change first-n-numbers
back to funs.
d. In the new copy, change the line that gives the filename to include the repository. For example,
;;; File: ;;; git-examples/utils.rkt
e. Save both copies and quit DrRacket.
f. Commit and push the first copy.
$cd /home/username/Desktop/Git/git-example$git commit utils.rkt -m "Rename first-n-numbers back to nums."$git push
g. Attempt to commit and push the second copy.
$cd /home/username/Desktop/git-example$git commit utils.rkt -m "Update introductory comments."$git push
h. You will likely find that the git push command failed
For example, here's an error message that I see.
$git pushUsername for 'https://github.com': rebelskyPassword for 'https://rebelsky@github.com':To https://github.com/rebelsky/git-example! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/rebelsky/git-example' hint: Updates were rejected because the tip of your current branch is behind hint: its remote counterpart. Merge the remote changes (e.g. 'git pull') hint: before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
What's going on? Git won't let you push a second set of changes until
you've incorporated the first set of changes. (Otherwise, you might
accidentally overwrite someone else's changes.) So, you need to pulll
in those changes. Typing git pull will bring in the
changes you've just pushed. (You may have to fill out a commit message.)
i. Open the file to see that it has both sets of changes (the change to the introductory comments and the change to the procedure name).
j. Type git log to see a list of all the changes that have
been made recently.
k. Send the updated version back to GitHub with git push.
l. Update your original repository.
$cd /home/username/Git/git-example$git pull
The two changes we just made were independent - at different locations in the file. What happens if we make two conflicting changes, changes at the same points in the file? Let's see.
a. In DrRacket, open both version of utils.rkt.
b. In one version of the code, change nums to
first-n-numbers.
c. In the other version of the code, change nums
to one-to.
d. Push one set of changes.
$cd /home/username/Desktop/Git/git-example$git commit utils.rkt -m "Rename nums to first-n-numbers."$git push
e. Attempt to pull the changes in the other version.
$cd /home/username/git-example$git pull
You should see a message like the following.
error: Your local changes to the following files would be overwritten by merge:
utils.rkt
Please, commit your changes or stash them before you can merge.
f. Commit your changes to the local repository.
$cd /home/username/Desktop/git-example$git commit utils.rkt -m "Rename nums to one-to."
g. Trying pulling again.
$git pull
You'll get another error, this time because there's a conflict.
Auto-merging utils.rkt CONFLICT (content): Merge conflict in utils.rkt Automatic merge failed; fix conflicts and then commit the result.
This time, it's actually pulled the code and made a hybrid file wiith both sets of changes.
h. Open utils.rkt in DrRacket and see what's happened.
i. You are likely to see lines like the following
<<<<<<< HEAD (define one-to ======= (define first-n-numbers >>>>>>> 26083cbe308f74b692ae1be872676d020a13a360
These represent the change from your file and the change from the other copy. You need to choose one of the changes and remove the other change, along with the additional text
j. Once you've manually dealt with the conflicts, save the file and quit DrRacket.
k. Commit your changes and push them back to GitHub.
$git add utils.rkt$git commit -m "Resolve conflict using by ..."$git push
We noted that one reason to use source code management systems is that SCMs give you access to old versions of your work. Let's see how.
a. Navigate to the project on GitHub. For example, you might go to https://github.com/username/git-example.
b. Click on the link for utils.rkt.
c. Click on the button. You should see a list of all of the changes that you've made, along with some additional notes.
d. Click on for an old version to see the source code for the old version.
e. Click your browser's back button to return to the list of history.
f. Click on one of the strangely named buttons over . (Those weird names are ways to identify different versions. They are generated algorithmically.)
g. Describe what you see.
One of the important aspects of GitHub is that multiple people can use the same repository. How? You generally need to invite collaborators.
a. Navigate to the project on GitHub. For example, you might go to https://github.com/username/git-example.
b. Click on the button that's on the right side of the screen, near the middle.
c. Click on the button.
d. Enter your Professor's username and click .
e. If you're working in a group, add any group members as collaborators.
Figure out how to add another file to your repository.
Go to the repository for the course software, available at https://github.com/GlimmerLabs/gigls. Determine what change was made on March 27, 2014 and why that change was made.
By playing on GitHub (including in the gigls repository), by reading documentation, or by searching the Interweb, find one other interesting thing you can do with Git or GitHub.
Each member of the group should fill out the form at http://bit.ly/151githw.
git config --global user.name "Your Name" git config --global user.email your_email@example.com git config --global core.editor editor git help git clone git add git commit git pull git push
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Setup] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Davis (2013F)] [Rebelsky (2010S)] [Rebelsky (2013F)] [Weinman (2012F)] [Weinman (2014S)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)]
Samuel A. Rebelsky, rebelsky@grinnell.edu
Copyright (c) 2007-2014 Janet Davis, Samuel A. Rebelsky, and Jerod Weinman. (Selected materials are copyright by John David Stone or Henry Walker and are used with permission.)

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by-nc/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.