Submitting (5 points)
In this course, we’re going to be using GitHub. GitHub uses Git which is a version control system used by programmers. We’re going to learn a lot more about Git later, but for now, let’s use its most basic functionality.
Go to GitHub and create an account, if you don’t already have one. Many of the courses in the computer science major will require using GitHub so you’ll be well-served by getting comfortable with it now.
Go to the GitHub Classroom assignment page and accept the assignment. Wait a few seconds and then reload the page and you should see “You’re ready to go!” Click the link for the assignment repository.
The repository it created should be at a URL like
https://github.com/systems-programming/lab1-accountname
. The last component
of the URL will be some combination of the lab name and your GitHub user name.
You will need this in the cloning step below.
Next, you need to clone the assignment repository which will download all of
the files (if any) in the remote repository on GitHub to your computer. To do
this, you’ll need to use gh
to authenticate to GitHub and then perform the clone.
gh
is the command-line tool for working with GitHub. Most of the time, you
will use plain Git commands, but for authentication and cloning repositories,
you’ll use gh
.
In a terminal, run the command
$ gh auth login
and then using the arrow keys, select GitHub.com
and press enter. Select
HTTPS
for the preferred protocol and press enter. When it asks to
authenticate Git with your GitHub credentials, type Y
and press enter. When
it asks how you’d like to authenticate, select Login with a web browser
and
press enter. Copy the one-time code it displays and then press enter to open
the browser. If it cannot open the browser, you can click
here.
In either case, paste the code you copied and login (which should only be
required if you have logged out of GitHub). Click the Authorize github
button on the web page. At this point, you should see something like
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
✓ Logged in as accountname
in the terminal.
Now you’re ready to clone your repository. (In future labs, you shouldn’t need to authenticate again unless you log out.) Run
$ gh repo clone systems-programming/lab1-accountname
where lab1-accountname
should match the URL for the repository described above.
At this point, you should have a directory named lab1-accountname
(where,
again, the actual name is specific to your repository). This is your
newly-created local repository.
Copy all of the files and directories from lab1
into the newly-created local
repository’s directory. Read the man page for cp
to figure out how to
recursively copy directories.
cd
to your local repository directory. The contents of this directory
(recursively) should look like this.
repo
├── books
│ ├── Joyce, James - Dubliners.txt
│ └── Stoker, Bram - Dracula.txt
├── task1.txt
└── task3.txt
We want to add the files to the repository, commit them, and then push them to GitHub. (We’ll talk about why there are separate steps later. You can think of these three operations as “inform Git about the current state of the files,” “have Git make a snapshot of the current state of the repository,” and “tell GitHub about the changes we made in the local repository.”
These are the commands you need to run.
$ git add books task1.txt task3.txt
$ git commit -m 'Submitting lab 1'
$ git push
If you make changes to a file, you need to run $ git add
and pass it the path of the file you changed again. And then you’ll need to run $ git commit
and finally $ git push
.
The -m 'Submitting lab 1'
causes Git to create a commit message with the
contents Submitting lab 1
. Normally, we’ll want to create more descriptive
messages, but this is fine for now.
At this point, you’re done! You can check that everything worked correctly by going back to your repository on GitHub and checking that all of the files and directories show up. You should see two directories and two files:
.github
books
task1.txt
task3.txt
The .github
directory was added automatically by GitHub Classroom. So why
didn’t it show up in your local repo? Because its name starts with a period!
Recall that files whose names start with a period are hidden. You can see the hidden files
using ls -a
. If you do this, you’ll also see a .git
directory
too. .git
is where Git stores its local configuration.
Finally, you can remove your lab1
directory that we started with now that
you’ve copied everything over to your local repository for lab 1. Since lab1
isn’t empty, $ rmdir lab1
won’t work to remove it. And since it’s a
directory, $ rm lab1
work work either! Go ahead and try both commands out.
Read the man page for rm
to figure out how to remove directories
recursively.
Following the instructions above regarding which files should appear in your repository and which must be removed is worth 5 points. Every subsequent lab also has 5 free points for following the submission directions.