CSCI 338: Fall 2023

Software Engineering

CSCI 338: Fall 2023

Assignments > Lab 2: Version Control and Branch Management with git and GitHub

Due on Wed, 09/06 @ 11:59PM. 6 Points.

Introduction

Today we will be practicing collaborating on code by using git and GitHub. Here are today’s slides.

Lab Readings

required Collaborating using Git and GitHub: Branches, Pull Requests, Merging vs Rebasing (Video walkthrough)
recommended What is git rebase?
recommended Article explaining how to rebase + handle merge conflicts

Your Tasks

1. Add your GitHub username to the spreadsheet

If you haven’t already, please register for a GitHub account, and then add your full name and your GitHub username to this spreadsheet. Semmy and I will invite you to be a contributor to the relevant repos.

2. Set up public / private key authentication for GitHub (and Arden)

When accessing a remote server (including a GitHub server), a common authentication strategy involves using public and private keys. Below, you will go through the process of generating a public / private key. Your private key is for you and you alone. It is your secret, and should not be shared with anyone. Your public key, on the other hand, is typically copied to a server for which you have access.

In the workflow outlined below, all commands should be run from the command line on your local computer (not arden). If you’re a Windows user, activate WSL.

2.1. Generate a public / private key pair

To generate a public / private key pair:

2.2. Copy your public key to the appropriate place

On GitHub
  1. Follow the GitHub instructions
  1. Copy your public key into your home directory on arden. One way of doing this is by using the rsync utility:
    rsync ~/.ssh/id_rsa.pub <your_arden_username>@arden.cs.unca.edu:~/.
  2. Configure your public key on arden:
    • ssh into arden: ssh <your_arden_username>@arden.cs.unca.edu
    • Verify that the id_rsa.pub file is now in your home directory.
    • If your home directory on the remote server doesn’t already contain a ~/.ssh/authorized_keys file, create oneas follows:
      • mkdir -p ~/.ssh
        touch ~/.ssh/authorized_keys
    • Then, append your public key to the authorized_keys file: cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
    • Finally, delete your public key from your home directory on arden (you don’t need it anymore):
      rm ~/id_rsa.pub

That should be it! Read More here: https://kb.iu.edu/d/aews

3. Set up a local copy of the coursework repository

In this class, we’re going to have two repositories:

Before we get into the details of the GitHub workflow, let’s set up a clone of class-exercises-fall2023 on your laptop while practicing some basic git commands. Please complete the following tasks:

  1. Within your csci338 directory, clone the class-exercises-fall2023 repo using the ssh method (while in the csci338 directory on your local computer):
    git clone git@github.com:csci338/class-exercises-fall2023.git
  2. Look at commit history (git log)
  3. Create a new branch called <your-username>
    • For instance, Sarah would create a branch called vanwars: git checkout -b vanwars
  4. Create a folder named <your-github-username> (e.g. Sarah would create a folder called vanwars) within the class-exercises-fall2023 folder on your new branch.
  5. Within the <your-github-username> folder, create a text file called README.md (note the case).
  6. Within the README.md file, add the sentence “hello world!” (or anything, really). You can use vim, VS Code, or another text editor.
  7. Issue the git status command. What happened?
  8. Stage your changes using git add . (the dot indicates that you want to stage all of the files that have been added / deleted / edited).
  9. Commit your changes using git commit -am "adding my user directory".
  10. Push your branch to GitHub (git push)
    • Note, typing git push will display an error with a suggested push command (e.g., git push --set-upstream origin <your-branch-name>).
  11. Create a pull request.

A note on your origin path

Within git, your remote origin variable holds both the address and the protocol you will be using to interact with a remote server (like GitHub). Some of you are accessing the remote server using the https protocol while others are using the ssh protocol. For the sake of simplicity, let’s all use ssh. To check your origin, type: git remote show origin.

If it prints git@github.com:csci338/class-exercises-fall2023, you don’t have to do anything. Otherwise, let’s switch up your origin protocol to ssh as follows:

1
2
3
git remote rm origin  # removes current references
git remote add origin git@github.com:csci338/class-exercises-fall2023.git  # adds new reference
git remote show origin  # prints the new origin (which should be the correct one).

4. Set up the course project repo

4.1. Clone app

  1. Within your csci338 directory, clone the course app repo via ssh:
    git clone git@github.com:csci338/app.git
    • Be sure you don’t accidentially put app underneath class-exercises-fall2023.

4.2. Make a new branch

  1. Create a new branch called <your-username-readme>
    • For instance, Sarah would create a branch called vanwars-readme: git checkout -b vanwars-readme
  2. Open the existing README.md file. At the bottom, add an entry with your name and your GitHub username. Please add your information so that the table is sorted in alphabetical order by last name.
  3. add, commit, and push your changes to a remote branch of the same name.
  4. Create a pull request

4.3. Resolve push / pull conflicts

  1. Once your branch is approved, check it to ensure that there are no conflicts with the main branch.
  2. If there are conflicts, follow the steps below:
Workflow for resolving conflicts
1
2
3
4
5
6
7
8
9
10
11
git checkout main  # checkout the main branch again
git pull # pull down the changes that have happened since you last pulled / cloned
git checkout <your-username>-readme # switch back to your branch
git rebase main # try to rebase

# Manually resolve the conflict and then continue steps below...

git status
git rebase --continue  # continue the process
git push # should reject your change
git push --force # force the change

4.4. Incorporate your changes to main

When you’re done, ask Semmy or Sarah to incorporate your changes to main.

What to Turn In

Make sure that the following are completed before Wednesday (9/6) at midnight: