Lecture 5 – Sep 13th, 2019
- Create an account on GitHub using your Oberlin email address if you don’t already have one. If you already have an account, you can add your Oberlin email address on the appropriate settings page.
- Log in to GitHub and then visit this page and click the
Accept this assignment button.
- After a few seconds, the repository will be ready, click the
https://github.com/systems-programming/playground-username link that appears (it won’t be literally
playground-username, it will have your GitHub username.
- Log in to clyde.
- Run the following commands, but substitute your name, email address, and editor of choice in the appropriate spots
$ git config --global user.name 'YOUR NAME HERE'
$ git config --global user.email 'YOUR.EMAIL@oberlin.edu'
$ git config --global core.editor 'YOUR EDITOR'
- Under “Quick setup” on the GitHub page you opened in step 3 of the Setup, click the
HTTPS button and copy the URL to the right of it. Run
$ git clone https://github.com/systems-programming...
where you replace
https://github.com/systems-programming/... with the actual URL you copied.
cd into the directory
git clone just created. There are no files there yet, so open your editor of choice and create a
README file. It’s traditional to include information about what the project is, how to build/install it, and examples of usage. In this case, the project is called
Playground. Mine contained these contents.
Information about what playground does here.
$ git add README to add
README to the staging area.
$ git commit to commit it. This will open the editor you configured above. Enter a commit message. The first line should be a short summary. Then add a blank line, and starting on the third line, you can give a more detailed explanation of what you’re committing. Write your commit message, save the file, and exit the editor. If all has gone well, your file will be committed.
$ git push to push the new commit to GitHub. You’ll need to enter your GitHub username and password.
- Reload the GitHub page in your browser from step 1. You should see your
README in the repository and GitHub will display the text in the page below the file listing.
- That README is okay, but it’s kinda boring. It’s just plain text. Let’s replace it with one we can write in Markdown. Use
git mv to rename
README.md. You can read more about Markdown later. For now, use lines starting with
# to make section headings.
Information about what playground does here.
# Usage examples
# Build instructions
$ git status to see some information about the files in the repo. You should see under “Changes to be committed” that the file was renamed and under “Changes not staged for commit” that the file was edited.
- To see what would be committed if you were to run
$ git commit right now, run
$ git diff --cached. This is the difference between what’s in the repo and what has been staged by the
git mv earlier.
- To see the difference between what is in your working directory and what has been staged, run
$ git diff (without the
--cached). Lines in red (starting with
-) will be deleted. Lines in green (starting with
+) will be added.
- Stage your changes by running
$ git add README.md.
$ git status,
$git diff --cached, and
$ git diff to see what changed from before the
- Commit the changes with an appropriate commit message.
- Reload the GitHub page for the repository. You’ll see nothing has changed. Why not? What step did we forget? Perform that step.
- Reload the page again after performing the missing step.
- Try creating and adding new files and directories. Commit them. Modify some files, commit your changes. View your changes using
$ git log
- Just for fun, read Steve Losh’s Git Koans.
Make life easier
Entering your username and password every time you push or pull from GitHub is terrible. You definitely don’t want to have to do that every time. There are two options to make life more pleasant for you.
The first is to use the “git credential helper” to securely store your credentials. See this StackOverflow answer for some details.
The second method is to give GitHub your SSH key. This is the method I usually use. Note that the instructions for generating an SSH key say to use
$ ssh-keygen -t rsa -b 4096 -C "firstname.lastname@example.org"
but I would suggest the following instead.
$ ssh-keygen -t ed25519 -C "email@example.com"
Note that the key pair you generate this way will be called
id_ed25519.pub instead of
id_rsa.pub. The only real advantage here is that Ed25519 is much faster than RSA.
If you use the second method, the URI you want to copy for cloning will be
firstname.lastname@example.org:systems-programming/... rather than