Lab 13: Git / GitHub

When working with a partner, how can you both work on the program at home, and keep track of the differences? How are companies with hundreds, or even thousands, of software engineers able to allow them to work on the same codebase? Even developing on your own, what is a good way to save your work as you go along?

The answer to each of these questions is version control, which simply means a system used to keep track of changes made to software and the different versions of the code that have existed. We have seen examples of this in both Replit and Gradescope, where you can look at the history of different versions. While there are many available options to do version control, git and GitHub are widely used in academia and the industry. This is what we will explore in lab this week.

Git is version control software that lets you manage and keep track of your source code history. It can work on a local machine. GitHub is a cloud-based hosting service that lets you manage Git repositories. [Curious about the name git? see here.]

Lab Preparation

We will be using git on Replit, so that both you and your partner will have the same preparation and environment to work in. Git on Replit works similarly to how we are able to run gdb and gprof in the console.

  1. Install git on your local machine by following the instructions (LINUX, MacOS, Windows) on this page:
    https://git-scm.com/book/en/v2/Getting-Started-Installing-Git.
    After following the above installation instructions, configure the setup of your git name, email, default editor and other options by following these steps:
    https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup.

  2. Set up a free GitHub account using the GitHub Student Developer Pack, if you do not have one already. All that is required is an email address that ends in .edu. This gives you additional features, compared to the basic GitHub version.

3. Create a new repository on GitHub, either from GitHub or from your local editing environment (e.g. Replit). You can have any C code in the repository that you are comfortable with having your partner be able to view and edit. If you make it public it will simplify your lab activity, but you wouldn't necessarily want to use it later for class work if it is public.

If you are using the command line in Replit, you will need to redefine your git environment each time (since we don't have administrator permission in Replit) using the following commands from the command line each time you start Replit (except with your own information and editor preference [e.g. nano] in it):
git config --global user.name "Dale Reed"
git config --global user.email
reed@uic.edu
git config --global core.editor vim
git config --global init.defaultBranch main

Lab Outline

Now that you have git and a GitHub account, do some online research on the git commands shown below and practice using them. (If you don't know where to start looking for information, the Pro Git book is an excellent resource, with detailed explanations and examples of the numerous features of git.) Explore these commands in the order that they are shown, as some of the commands may be dependent on a previous one. Each of the commands below can be run with git in front, e.g. git clone or git status.

config, clone, diff, status, add, rm, commit -m, push, pull, log
For your outline, create a summary of each of the git commands listed above. For each command provide:

  1. A brief explanation of what the command does

  2. An example of using it within the Replit environment you have setup

  3. A description of how the git command affects your repository on GitHub.

Submit your outline to the same Reading Outline Submission Form that we have been using.

Lab Activity

  1. One person in your group should clone this repository ( https://github.com/ekidane/211-f22-collab-github.git ). If you are doing this from within Replit (and not your own command line on your own git installation on your own machine), then see these instruction on using git with Replit
    After you have cloned the respository, within the repository
    edit collab.c and create a function that outputs your name, along with either one thing that you learned about git or GitHub or something that gave you trouble that you would like others to learn from. The function name should be your NetID combined with your partner's NetID, such as reed_ekidan2. Feel free to add other things to your function as well, though be mindful of the length of it, given how many students will be collaborating on this code! Be sure to read through the code that is already there before adding your own. Add this code to the repository using git commands.

  2. On your slide, explain your process of cloning, modifying, and updating this collaborative repository, using the information that you prepared for your lab outline. Copy/paste examples and/or screenshots to help describe the process and aid in overcoming any challenges that may arise.

  3. Time Permitting: If you would like to explore further, look into the use of branches and pull requests. One of the many uses of these is to allow you to work on a new feature of the software, without worrying about if your new code will break the main codebase. You can join your partner's repository, and see how to:

  • Create a new branch

  • Switch to a new branch

  • Make changes to just that branch

  • Merge the branch into main

Chapter 3 of the Pro Git book will be especially helpful in learning how these work.