Git Setup
Table of contents
csse341 Labs
We will maintain all the labs and homework coding problems in this under one repository that you can find on GitHub using this link. We will be updating this repository with new labs and homework problems as we continue with the quarter, so it is essential that you keep track of it.
At the same time, you should maintain your own code in a private repository so that you never lose your progress and can work across different machines. In what follows, we detail the steps necessary for you to maintain a private course repository that can obtain updates from our labs and homework problems.
1. Create a private repository
Using your GitHub account, create a new, empty, and private repository. Do not initialize that repository with a README file, do not create a license, and make sure that the repository is completely empty.
The repository you create will host all your source code for submitting labs, so we suggest you give it a meaningful name, such as csse341-labs-<username> where <username> is your Rose-Hulman username. For example, I would want to create a repository called csse341-labs-noureddi. In what follows, we will assume that you called your repository csse341-labs-user.
Please make sure that your repository is private. Creating a public repository and hosting your solutions on it is a form of academic misconduct and we will treat it as such. If you are not sure whether you have create a private or public repository, please always check with your instructor.
1.5 Create and add your ssh keys
To clone your repository and make changes to it, you need to have your Linux ssh keys added to your GitHub account. Please create those under your Linux distribution and not PowerShell or GitBash.
Are you using GitBash? If yes, then please stop and switch to your Linux terminal.
- Generate your public/private key pair using
$ ssh-keygen Generating public/private ed25519 key pair. Enter file in which to save the key (/home/csse/.ssh/id_ed25519): Created directory '/home/csse/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/csse/.ssh/id_ed25519 Your public key has been saved in /home/csse/.ssh/id_ed25519.pub The key fingerprint is: SHA256:8TU+r6RvCGsSJEmbvsuBqpgQ5x8lICVkmZZ8eNFwuIc csse@hegel The key's randomart image is: +--[ED25519 256]--+ |+o*o=. | |.X +o. | |o +.o+ . o | | . E=.. o o . | |. ..oo. S . o | | + ..o. . o | |. o o. . o .. . | |oo o.o. o .o.. | |* +. o .oo | +----[SHA256]-----+ Your key is saved under the
.sshdirectory in your home directory. In Unix, any directory that starts with a.is a hidden directory, so you will not see it using a visual file explorer, yet you can still access from the terminal.Check out the content of that directory using
ls ~/.ssh. Here,~refers to your home directory, which is/home/usernamewhereusernameis your Linux username. You should see at least two files there:id_ed25519.pubis your public key whileid_ed25519is your private key.- Read the content of your public key and copy it to the clipboard.
$ cat ~/.ssh/id_ed25519.pub Navigate to your GitHub account setting page by clicking on the user icon in the upper-right corner. Then select
settingsfrom the drop down menu.On the settings page, select
SSH and GPG Keysand click the greenNew SSH Keybutton.- Give the key a unique name (e.g., csse341 Linux key) and then paste your public key into the large text box. Finally, click the
Add SSH Keybutton and you are all set.
Hint: When navigating directories and files in a Linux terminal, you can use the Tab key to autocomplete file and directory names. Type out the first few letters of the file or directory name and then hit Tab for autocompletion. If nothing shows up, then either there is not such file or directory with that name, or more than one exists. Hit the Tab key again and you will hear an alarm sound if no such name exists or a list of possible matches will show up in the case where there are multiple matches.
2. Clone the repository
After adding your ssh keys to your GitHub account, copy the ssh URL of your private repository and clone it under your Linux distribution.
Please pause here and make sure that you are not cloning the repository using PowerShell or GitBash. Cloning using either will create all sorts of issues when accessing Windows partitions form your Linux distribution.
No seriously, please don’t clone the repository using GitBash.
For example, for my own private repository, I used:
$ git clone git@github.com:nouredd2/csse341-labs-noureddi.git
...
warning: You appear to have cloned an empty repository.
Please note the line that says warning: You appear to have cloned an empty repository. If that line does not show up, then you most likely have chose to create a README or LICENSE file on your repository. You should make sure that the repository is completely empty!
3. Adjust the repository’s remotes
We would like to set up your repository in a way that you can pull from two locations:
origin: that would be your own repository (in case you need to move between devices).upstream: that would be the class’s repository containing new labs.
However, when you finish a lab and commit your changes, we would like to push those changes to your private repository, i.e., only to origin.
To do so, first navigate to your labs repository:
$ cd csse341-labs-user/
Your directory should be empty (confirm that using ls). Next, let’s add a new upstream remote pointing to the class repository as follows:
$ git remote add upstream https://github.com/rhit-netsos/csse341-labs.git
To confirm that the remotes have been updated, check using:
$ git remote -v
origin github.com:user/csse341-labs-user.git (fetch)
origin github.com:user/csse341-labs-user.git (push)
upstream https://github.com/rhit-netsos/csse341-labs.git (fetch)
upstream https://github.com/rhit-netsos/csse341-labs.git (push)
4. Fetch changes from the class repository
Now, grab the latest changes from the class repository using:
$ git fetch upstream
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 2.51 KiB | 366.00 KiB/s, done.
From github.com:rhit-netsos/csse341-labs
* [new branch] main -> upstream/main
Then, pull the changes:
$ git pull upstream main
From github.com:rhit-netsos/csse341-labs
* branch main -> FETCH_HEAD
Now, if you check the content of your directory, the starter code for the labs will show up in there. Confirm that using ls.
5. Push your initial commit to your private repository
Now, we need to sync things up to your private repository, to do so, you should use:
$ git push origin main
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 2.53 KiB | 2.53 MiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:user/csse341-labs-user.git
* [new branch] main -> main
Using your browser, verify that everything now shows up on your csse341-labs-user private repository.
6. Making changes
When attempting the labs, you can treat this repository just like any other private repository where you can maintain your code. Say you modified a file called solution.c, then you can follow this workflow to push it to your private repository.
Add the file to the change list:
$ git add solution.c
Commit your changes:
$ git commit -m "finished lab 1"
Push your changes:
$ git push
This will push the changes to your own private repository. If you run into any issues when pushing, you can be more specific about where to push the changes using:
$ git push origin main
7. Tips and tricks
Recall that at any time, you can check the status of your repository using:
$ git status
Also, to add all modified files in one shot (without adding them manually), you can use:
$ git add -am "finished lab 2"
Note that the above command will add all modified files to the change list, but will not add your newly created files (if any). If you’d like to commit and push new files, then you should add them manually using git add.
Finally, please do not commit any object files (.o), binary files (executables), vim swap files (.swp), and anything that is compiled and generated, those will create a mess if you work across different devices and will pollute your repository.
When we add a new lab assignment, you can obtain the added changes using:
$ git pull upstream main
Then push those changes to your private repository using:
$ git push origin main
We will organize things in separate folders to minimize merge conflicts as much as possible. If you work within each lab’s own directory, you should not have any conflicts arise from obtaining new changes from the class repository.
If at any point in time, you made changes to a file, say lab1.c, but would like to restart your lab, you can restore the file to its original version from the class repository using:
$ git checkout upstream/main -- lab1.c
Note that this will discard all changes you have made to lab1.c, so make sure that this is really the behavior you would like to see.