Week 5 Exercises: Git and GitHub
Introduction
In this exercise, you’ll practice with creating and pushing to GitHub repositories.
Setting up
- Start a VS Code session through OSC OnDemand in the folder
/fs/ess/PAS2880/$USER
.
Exercise 1: GitHub
Go to the GitHub website, log in, and create a new GitHub repository. This will be the remote counterpart of the Git repo you made as part of last week’s assignment. You can give the GitHub repo any name you want.
In the terminal in VS Code, navigate to your dir for last week’s assigmment. Then, use Git commands to set up a connection between the Git repo and the GitHub counterpart.
Push your local repo to the online counterpart.
Explore your repo on GitHub. Does your
README.md
render well? Can you see all your commits?Open a GitHub Issue for your repo: on the GitHub page for your repo, in the Issues tab, click “New Issue”, and in the box where you can type your issue, tag the instructor. For example:
Hey @jelmerp, can you please take a look at my repo?
(You will use this approach to “hand in” the remaining assignments for this course.)
Back in VS Code, add a line to your
README.md
that mentions you created a Github repo on today’s date, adding the repo’s URL.Commit the change to
README.md
to your Git repo.Push to the remote and check that the changes were applied in the online repo.
Solutions
Exercise 1
2. Navigate, then set up a connection to the online repo
cd GA2
# (replace <SSH-URL-to-repo> with your actual SSH (not HTTPS!) URL)
git remote add origin <SSH-URL-to-repo>
3. Push your local repo to the online one you just created
When you push to a remote repo for the first time, you need to add the -u origin main
part:
git push -u origin main
7. Commit the change you made to README.md
git add README.md
git commit -m "Update README with GitHub repo information"
8. Push to the remote
Since you’ve pushed to this remote before, a simple git push
works:
git push