Hello, World!
This in-class activity is designed to introduce you to using git-keeper, the SQLite command line tool, and Markdown.
You should have gotten two emails from git-keeper: one with a username and password for the server, and one with a Git clone URL for this activity.
Git-keeper Assignments
The workflow for most git-keeper assignments will be as follows:
- Receive an email with a clone URL for a Git repository on the server
- Clone the repository using the URL from the email
- Do your work in the local clone of the repository
- Add and commit your changes to the local repository
- Push your changes back to the server
- Check your email to make sure the submission was received and see the results of any tests that were run.
Cloning a Git Repository
A Git repository stores the current version of a project’s files, along with the history of changes to the repository and some other metadata. When you clone a repository from a server, you get a local copy of the repository on your computer.
Create a directory (also known as a folder) on your computer to store assignments for this class. This guide assumes that you created a directory on your desktop named cs232
, and that your username is username
. You may put the directory wherever you want, but you will have to change the commands below accordingly.
Open up a command line terminal. This will either be the Terminal application in macOS or the Windows Subsystem for Linux (WSL) distribution that you installed if you are on Windows.
Now you need to navigate to the directory that you created for the class. You can do this with the command cd
(which stands for change directory). On macOS you will want to do this:
cd Desktop/cs232
If you are using WSL, the path to the directory will be a bit longer:
cd /mnt/c/users/username/Desktop/cs232
When using the command line you are always in a working directory. You have now changed your working directory to be your class directory. You can see what your working directory is by typing the command pwd
(print working directory).
Now you can clone the repository for this activity. Copy the clone URL from the email that you received from git-keeper. Replace the URL in the command below with the one you got in the email:
git clone nsommer@gitkeeper.wooster.edu:/home/nsommer/nsommer/cs232/in_class-hello_world.git
You will be prompted for a password. Enter the password you received in the email from git-keeper. For security reasons you will not see any characters as you type the password.
If all goes according to plan you should see output like this:
Cloning into 'in_class-hello_world'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.
The command ls
lists files and directories. If you run ls
now you should see a single directory called in_class-hello_world
.
Navigating into the Cloned Directory
Run the following command to change your working directory to the directory you just cloned:
cd in_class-hello_world
Now run ls
and you should see 2 files: github_username.md
and hello_world.sql
.
Note that you can see these files in macOS’s Finder or in Windows Explorer too. Open up the directory that you created on the desktop and you should see the in_class-hello_world
folder, and inside there you should see the two files.
Editing github_username.md
Now open the file github_username.md
in the text editor that you installed.
Files that have the extension .md
are Markdown files. Markdown is a markup language that lets you write documents in plain text, and then other programs can render the documents in a nice format, such as a PDF or an HTML page. Other markup languages include HTML and Latex. Unlike many other markup languages, Markdown aims to be nicely readable in both plain text and when rendered.
github_username.md
already contains some Markdown:
# GitHub Username
Enter your name and GitHub username below:
* Name:
* GitHub Username:
In your text editor, add your name and your GitHub username and save the file. Note that your GitHub username is not the same as your git-keeper username. You should have created a GitHub account on your own before this class session.
Using SQLite
Now let’s make sure the SQLite command line utility works correctly on your computer. The file hello_world.sql
contains two commands in the Structured Query Language (SQL). You can print the contents of this file in the terminal by using the command cat
:
cat hello_world.sql
After running this command you should see the following:
CREATE TABLE message(message TEXT);
INSERT INTO message VALUES('Hello, world!');
We will talk about SQL in much more detail this semester. For now all you need to know is that the first command creates a database table named message
, and the second inserts the string 'Hello, world!'
into that table.
The SQLite command line utility is called sqlite3
. An SQLite database is stored in a single file, and the sqlite3
command can be used to access and manipulate data in an SQLite database.
We want to create a new database and run the two SQL commands in hello_world.sql
in that database. The database will be created in the file messages.sqlite
. To accomplish this, run the following command:
sqlite3 messages.sqlite < hello_world.sql
Running sqlite3
with the name of a database file that does not yet exist will create that file. The < hello_world.sql
portion of the command means that the contents of the file hello_world.sql
will be used as the input to sqlite3
, and the commands will be executed.
Now run the command ls
and you should see three files, including the file messages.sqlite
.
Now let’s use sqlite3
to interact with the database. Run this command:
sqlite3 messages.sqlite
This will not run any commands on the database, it merely opens up the database and provides an interative environment where you can type in commands. You should see something like this:
SQLite version 3.13.0 2016-05-18 10:57:30
Enter ".help" for usage hints.
sqlite>
You may run commands at this prompt. Let’s query the database to make sure the data that we asked be inserted was indeed inserted into the table message
. Type the following command at the prompt:
SELECT * FROM message;
You should see Hello, world!
printed.
Now let’s insert another string into the database. You may replace the string in my example with any string you choose:
INSERT INTO message VALUES('Here is another nifty message');
Now if you re-run the SELECT
query above you should see the following:
Hello, world!
Here is another nifty message
Committing and Pushing your Changes
For this activity, you only need to commit your changes to github_username.md
to the repository. Before you do that, you need to make Git aware of your name and email address. Run the following two commands, replacing "Your Name"
and youremail@wooster.edu
with your name and email address. Note that the quotes around your name are required so that it is interpreted as a single string. You only need to do this once and Git will remember your details.
git config --global user.name "Your Name"
git config --global user.email youremail@wooster.edu
Now let’s see the status of the repository. You can see the status by running git status
. Run git status
and you should see the following:
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: github_username.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
messages.sqlite
no changes added to commit (use "git add" and/or "git commit -a")
You can see that github_username.md
was modified since the last commit, and the file messages.sqlite
is not tracked by the repository. You do not need to submit the file messages.sqlite
for this activity, only the changes to the file github_username.md
.
Before committing, you need to stage the changes that you want to be committed using git add
. Stage the changes to github_username.md
by running the following:
git add github_username.md
Now run git status
again and you should see this:
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: github_username.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
messages.sqlite
Now you can see that when you commit your changes, only the changes to github_username.md
will be committed.
When you commit to a repository you need to provide a commit message. Commit to the repository with a message like so:
git commit -m 'Add my GitHub username'
Now when you run git status
you should see this:
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
messages.sqlite
nothing added to commit but untracked files present (use "git add" to track)
To see the log of commits to the repository, run git log
. You should see 2 commits: the commit you just made, and the initial commit made by git-keeper. Press q
to exit the log.
Now push your changes back to git-keeper by running git push
. You will need to enter your git-keeper password again. If everything works correctly, you should get an email from git-keeper confirming your submission.