P2
How to use git to solve and submit your exercises

You need git to send in assignments. You will receive the skeletons for your solution through git, presumably use git to version your intermediate steps, and when you’re all done, you’ll push your changes to the server, where we’ll grade them. This file tells you the basic commands that you’ll need to solve the exercises and to handle git.

Where to get git

If you’re using a Unix-like system (e.g. Linux, Mac OS X or Open Solaris) you can simply download and follow the instructions on the official web page.

Windows user have some more struggles. We highly recommend installing a Linux distribution like Ubuntu as this way you also get to know those kind of operating systems. But there is also a native Microsoft Windows port, called msysgit. A other possibility is the use of Cygwin for Windows.

Generate your ssh key

Here, and in the rest of this text, lines that start with a dollar sign ($) are to be issued on the command line and off course without the $-sign.

If you know what you’re doing, you can skip this. This creates your ssh key:

$ ssh-keygen -t rsa

You can (but shouldn’t) change the directory and enter a password but we do not recommend doing so.

Send us your ssh key

In your terminal go to the directory you saved your ssh-key and rename the public file with

$ cd /home/johndoe/.ssh/
$ cp id_rsa.pub john-doe.pub

(johndoe with your name, here and in the rest of this article.)

Mail the ~/.ssh/john-doe.pub (note: only .pub file!) to: joel.krebs@students.unibe.ch and add your name, matriculation number and your group colleague. Then, wait for your confirmation. You will get your group number with your confirmation.

Clone your group’s repository

$ cd 
$ mkdir P2
$ cd P2
$ git clone p2unibe@haddock.unibe.ch:group01

(replace 01 with your group number)

$ cd group01

Configure git

Issue the following commands:

$ git config --global user.name "John Doe"
$ git config --global user.email "doe@john.com"

$ git remote add p2ubungen p2unibe@haddock.unibe.ch:p2ubungen


(Replace John Doe and doe@john.com with your full name and email address)

Get exercise skeletons

These are the code skeletons that you will have to adapt or look at for completing your tasks. The following command copies the skeleton into your repository.

$ git pull p2ubungen master

Set up Eclipse

Eclipse is the program where you’ll write your code. Get it from eclipse.org.

Now, open Eclipse. Set your workspace to the folder: “group01”, i.e. the repository root.

Import the p2-tasks by choosing from the menu:
 File > Import … > General > Existing Projects into Workspace.

Git Workflow

Here are the commands that will get the code into your local repository, and into the public server, that your group and the TAs can see.

Retrieve latest exercise skeletons from server

$ git pull p2ubungen master

Create a topic branch

Every time you work on changes that go together, you should do so in a topic branch. The version history gets more readable that way.

$ git branch Problemset1
$ git checkout Problemset1

As soon as you’re finished working on your branch or you like to take a break you probably like to keep the changes you did and add a comment. (It doesn’t has to be a good comment on your topic branch but it has to be good on the master branch!) You commit like this:

 $ git add .
$ git commit

And as soon as you’re finished with the current task you can merge it into the master branch. Therefore you should checkout the branch you’d like to merge in.

$ git checkout master 

Then you merge the Problemset1 branch into the master branch. The —squash option allows you to choose a good comment now, which is mandatory by the task.

 $ git merge --squash Problemset1 
$ git commit

Good Comment:

One sentence describing the new state of the code

Newlines

Detailed explanation what you exactly did and changed. This part can be as long as necessary but remember: Brevity is the soul of wit.

Newlines

Names of the files that changed.

Example of a good commit message:

Problemset1 solved

Task: Implement a file filter. Solution passes
all provided unit tests, and we added a few more.  

Retrieve your group’s changes from server

$ git pull --all

Upload to server

$ git push origin master

Further reading

Rules for passing P2

  • All notifications will be posted on twitter. Please follow the twitter.com/p2unibe stream.
  • You’ll work in groups of exactly two students.
  • All but two assignments have to be solved. Assignments 05 and 08 are mandatory and cannot be skipped.
  • The first assignment is due on Friday at 12:00 (at noon).
  • The remaining assignments are due on Thursday at 12:00 (at noon). Be punctual!
  • If you flunk an assignment, don’t fret! You’ll be given the opportunity to fix your mistakes before the due date in the following week. After that, you may or may not get yet another chance.
  • Every week, one group will be asked to present their solution. You’ll be notified at least a day before you’ll have to present your solution. The presentation should be very nearly 400 seconds long. Test your timing before giving the presentation. It is mandatory.
  • All University rules apply. (Don’t copy somebody else’s solution!)
  • For questions and hints, you can:
    • Come to the Poolstunde on Tuesdays 16-18, in A95 (Exwi), or
    • Ask Andrei For technical questions, Andrei prefers if you ask your question on Stackoverflow and send him only a link to your question.