hw16: GitHub text messages
- Due before the beginning of class on Friday, February 16
Overview
This homework assignment asks you to create a git repository on GitHub and share it with one of your classmates. For today, we will just be using git as a simple folder to add files and send a text message to a classmate.
There is not technically much “work” in this HW like writing code, but you have to actually interact with your classmate in a few steps so it will be impossible to just complete this at the last minute by yourself. I recommend just sitting down with a classmate and getting it done.
You will have to download and fill in this markdown file to submit it.
Make a GitHub account
- Make an account for yourself on github, if you don’t have one already.
- Be sure to use your USNA email address so others can find you.
Note that GitHub is the de facto standard place to share and collaborate on coding projects. Many people seeking employment as data scientists share their GitHub profile to show off their work. So try to make a sensible username and consider adding a personal email as a secondary email address so that you can keep access to this account after graduating.
- What is your github username?
Create a new repo on GitHub
Login to github
Create a new repository (+ sign at top-right of window)
- Name your repo “hw16-YOU” where the YOU part is something short and unlikely to be chosen by any of your classmates, like perhaps your last name.
- Set it to private not public
- Go ahead and pick the default README and select the Python gitignore file.
- You can leave the licence as None.
Take note of the URL for your repo (question 2 below)
Add your instructor as a “collaborator”
- From your repo page, go to “Settings” and then “Collaborators”
- Click “Add people”
- Add your instructor by typing in their USNA email.
After you add, you should see their github username,
dsroche
for Prof. Roche, orluke8412
for Prof. McDowell
Add a classmate as a collaborator
- Find an SD212 classmate to partner up with on this part of the HW, and add them as a collaborator just like you did for your instructor above.
Get a classmate to add you as a collaborator on their repo as well
(It can be the same person you added as a collaborator to your repo if you want.)
What is the URL of your new git repo? (It should be something like
https://github.com/YOURUSERNAME/YOURREPONAME
)What classmate did you add as a collaborator on your repo? Enter their actual name as well as their github username.
What is the URL of your classmate’s git repo that added you as a collaborator?
Setup git and clone your repo(s)
Configure git
Open a terminal wherever you want to work on this HW (could be WSL on your laptop, or on a lab machine, or over ssh)
Note, it is definitely fine to work on a different machine later, but then you will need to re-run these setup commands.
Run these commands, replacing with your actual name and actual email address:
git config --global user.name "YOUR NAME" git config --global user.email "YOUR@EMA.IL" git config --global init.defaultBranch main git config --global pull.rebase false
Create an ED25519 SSH key. Run
ssh-keygen -t ed25519
Hit enter to accept the default file location.
If it says the file already exists, then you’re good; do not overwrite it.
Otherwise, when prompted for a passphrase, just hit Enter (leave it empty with no passphrase).
Display your SSH key on the terminal and copy it to the clipboard. Run:
cat ~/.ssh/id_ed25519.pub
which should display a single long line encoding your public key. Copy that entire line to your clipboard.
Login to github in a web browser
Add the new SSH key to GitHub: Click your login circle at the top right, go to “Settings”, then “SSH and GPG keys” on the left-hand menu, and then click “New SSH key”.
Paste your ed25519 public key from the terminal into the “Key” box and click “Add SSH key”.
Test it worked: Go back to the terminal and run
ssh git@github.com
You should see a message like this:
Hi <YOUR_GITHUB_USERNAME>! You've successfully authenticated, but GitHub does not provide shell access. Connection to github.com closed.
This is not an error! It’s just a check to make sure that your SSH key is set up correctly. If you see your own GitHub username there, then it means you’re all set.
Clone repos
On the terminal, navigate to your SD212 directory and clone your own git repo that you created before.
The command to clone should look something like this:
git clone git@github.com:YOUR_USERNAME/YOUR_REPONAME.git
If it works, this will create a directory with your repo name and a copy of all the files.
Do the same for your classmate’s repo that added you as a collaborator. It should make a separate folder for their repository.
Which git repos were you able to successfully clone?
- Just my own repo from question 2
- Just my classmate’s repo from question 4
- Neither one; I couldn’t get it to work
- Both!
(Write just the letter of your answer.)
Add files, git add, git commit, git push
Now we will follow a typical git workflow to actually add some content to these repos.
Here’s what you want to do, for both your repo and your classmate’s:
Create a new .txt file in that directory. You can call the file whatever you like and put any short message in it.
Save the file
Tell git about the file:
git add YOURFILE.txt
Add the new file to your local repo with a commit:
git commit -m 'YOURNAME added a file'
Sync your local repo with github
git pull git push
What is the name of the file you added to your own repo?
What is the name of the file you added to your classmate’s repo?
Pull changes from collaborator
Your collaborator(s) should also be adding their own files to the repos. This is the whole point of using git — to share code between people working on the same project.
After your classmate has added and pushed their new file to the repo, you just need to run this command from the terminal inside the directory for that repo:
git pull
Then you should see a new file added!
What is the name of the file your classmate added to your repo?
What is the name of the file your classmate added to their own repo that is shared with you?
Submit command
To submit files for this homework, run one of these commands:
submit -c=sd212 -p=hw16 hw16.md
club -csd212 -phw16 hw16.md
Download the file hw16.md to fill in and submit for this homework