Lecture 3 – Sep 13th, 2022
Setup
- 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/hw0-username
link that appears (it won’t be literallyhw0-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'
Task
- 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/somethingsomething...
where you replace
https://github.com/somethingsomething/...
with the actual URL you copied. cd
into the directorygit clone
just created. There are no files there yet, so open your editor of choice and create aREADME
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 calledHW0
. Mine contained these contents.HW0 Information about what this does here. Usage examples Build instructions
- Use
$ git add README
to addREADME
to the staging area. - Use
$ 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. - Use
$ 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 renameREADME
toREADME.md
. - Edit
README.md
. You can read more about Markdown later. For now, use lines starting with#
to make section headings.# HW0 Information about what this does here. # Usage examples # Build instructions
- Run
$ 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 thegit 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
. - Run
$ git status
,$ git diff --cached
, and$ git diff
to see what changed from before thegit add
. - 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 "your_email@example.com"
but I would suggest the following instead.
$ ssh-keygen -t ed25519 -C "your.email@oberlin.edu"
Note that the key pair you generate this way will be called id_ed25519
and
id_ed25519.pub
instead of id_rsa
and 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
git@github.com:somethingsomething/...
rather than
https://github.com/somethingsomething/...
.