CS 352 Homework 0, Part 2
Follow these steps to create your class homework repository and get homework 0 up and running.
1. Create a Bitbucket account
In this class, all your code will be stored with the Bitbucket webservice. Using this third-party service has some nice benefits: they maintain a complete history of your source code using some software called Git, you can access your code from anywhere, their servers are very reliable, and most professionals use Git or something like it to manage projects. Most importantly, your instructor will be able to access your code at any time. You won’t need to email or print any thing to submit. If you have a question, don’t “overshare” your code on Piazza. Just ask your instructor to have a look at Bitbucket.
Visit Bitbucket and create a new account—if you don’t already have one. Pick whatever username you’d like, but be sure to provide your real name so that your instructor can figure out who you are. You will need to remember your password, as you are likely to need it again soon.
2. Fork template repository
Next you will create a repository to hold all your code for CS 352. Bitbucket allows you to make many repositories, one for each project you work on. In this class, you will stick with one for the entire semester.
Your instructor has already created a template repository on Bitbucket. Your repository will be what Bitbucket calls a fork of this template repository. If your instructor adds or edits files in the template repository, you will be able to synchronize your fork with the template easily.
Find the template repository repository at https://bitbucket.org/twodee/cs352_2016c_template. You should see a page that looks like this:
Click on Source in the left navigation panel. You see a single directory. The
specs directory is where your instructor has placed all the homework writeups and graders. You should never modify, add, or delete files in
specs. Only you will suffer if you do.
In the left navigation panel, click on Fork to create your own repository based on this template. On the page that appears, expand Advanced Settings to see a screen that looks like this:
You can name your fork whatever you want—perhaps
cs352. There are two other things that you must get exactly right:
- Check This is a private repository.
- Check Inherit repository user/group permissions.
The other settings can be left at their default values. Click Fork repository to continue.
Click on Source in your repository. You should see the exact same files that were in the template. But these are your copies.
Return to your repository’s main page by clicking on Overview. Copy or make note of the
https://email@example.com/username/myrepo.git URL on the top-right. You will need this in the next step.
3. Clone your repository
You are done with Bitbucket in your web browser for a while. In fact, you will only rarely need to visit Bitbucket’s web page, as most of your time will be spent at the terminal, and the
git client can synchronize your files with Bitbucket directly. Go ahead and boot Linux and open a terminal.
So far your repository is only on Bitbucket’s servers. To add new files to it, you have to clone it on your Linux machine. Bitbucket holds onto your remote repository, while your clone is a mirror image of it on your local machine. After you finish making changes to the local mirror, you will send them up to the remote repository.
At the command line, enter this command:
git clone https://firstname.lastname@example.org/username/myrepo.git
myrepo with your actual user and repository names.
ls. You should see a directory for your repository.
4. Complete homework 0
Navigate to your repository using the file explorer for your Linux installation. Enter the
specs directory and double-click on
echoargs.pdf. If your machine has a PDF reader installed, the homework 0 specification appears. If not, you can find the homework specification on the course website or via your remote repository on Bitbucket.
Read the specification before proceeding further.
Learning goes something like this:
- You do something.
- You receive feedback.
Your instructor doesn’t want you to spend a lot of time in stage 1 and only a little time in stage 2. So, he has provided a tool called a SpecChecker that you can run as often as you want to see how well you are meeting the homework requirements. This tool isn’t designed to fix your problems for you—only to make you aware of them. You will still have to think.
Back at the terminal, enter your repository directory and make folder
cd myrepo mkdir echoargs cd echoargs
This directory will be a sibling to
To run the SpecChecker for homework 0, enter this command:
You should receive a message a message about the required script not being found.
4.2. Add echoargs Script
Let’s fix that error by adding an empty file with the appropriate name:
Run the SpecChecker again. It should complain that permissions aren’t correct. Run this command to give you, the file’s user, execute permissions:
chmod u+x echoargs
Now, open the file for editing and add this text:
#!/bin/sh echo "It is fun being in the same decade with you."
Franklin Delano Roosevelt wrote this message in a note to Winston Churchill.
Run the SpecChecker again. It will fail, stating your actual output doesn’t match the expected output. If you have installed
vim, you can visually compare the files with
Fix your file so that it actually loops through the arguments and echoes them:
#!/bin/sh for i in $*; do echo $i done
Run the SpecChecker again. No differences should be detected, but you will be asked if you’ve gotten your modifications up on Bitbucket yet—which you haven’t. You still need to get your code up to Bitbucket so your instructor can grade it.
5. Add Changes
Let’s see what
git says of the changes we’ve made:
It should list the current directory (
.) as an untracked file. Untracked files are known only locally. Technically, they don’t even exist in your local mirror, only in your working directory. You must add them.
You often want to bundle a set of related changes together, even if they occur across multiple files. Git provides a staging area or index where you can accumulate up your changes. Let’s add or stage the
git add echoargs
git status again and it will report that
echoargs is a new file, yet to be committed.
To move files that have been added to the staging area into the local mirror, you must commit them. Run this command to do so:
You will be prompted to describe the set of changes you have staged. Provide a short but meaningful description.
After the commit succeeds, your changes have made it into the local mirror of your repository!
But the local mirror is not synchronized with the remote repository on Bitbucket. You can tell this by running
git status. It will report that you are ahead by 1 commit. Run this command to push your commits from the local mirror up to Bitbucket:
Your last step is to verify that the push succeeded. Visit your repository in the web browser. Click on Source and navigate to the
echoargs script. If you can see it on Bitbucket’s web page, then so can your instructor—assuming you set up permissions correctly.
If you only ever use one machine, and neither you nor your instructor ever makes mistakes, this is really all you need to know to use Bitbucket and Git this semester!