Computer Science 491
Senior Seminar

Dickinson College
Fall Semester 2018
Grant Braught

Git/GitHub Workflow Activity
Introduction

Many H/FOSS projects use GitHub as the repository for their source code. This activity is designed to familiarize you with the common workflow elements for interacting with H/FOSS projects hosted on GitHub. The activity is divided into four parts:

  1. Part 1 - Before the First Class: You will complete this before the first hands-on class period with Git/GitHub. It will walk you through the process of configuring git, forking a repository on GitHub, cloning that repository to your local machine, and setting up an upstream remote in git.
  2. Part 2 - Hands-On in the First Class: You will complete this part hands-on during the first class period. It will walk you through the process of claiming an issue, creating a working branch, fixing the issue, pushing the fix to your GitHub repo, making a pull request, and keeping your local and remote repos into synch with upstream changes.
  3. Part 3 - Before the Second Class: You will complete this part following the first class period and before the second. In it you will repeat the process of claiming an issue, creating a branch, making a fix, pushing the fix to your GitHub repo and making a pull request.
  4. Part 4 - Hands-On in the Second Class: You will complete this part hands-on during the second class period. It will walk you through the process of resolving conflicts with concurrent upstream changes. You will synchronize your repos with the upstream, use a graphical merge tool to resolve conflicts and update your pull request before finally resynchronizing your repo with the upstream one final time.

Prerequisites:

A basic familiarity with git is helpful before beginning this activity. The following sites provide good starting points:

Have completed the Software Installation activity. All work for this Git/GitHub Workflow Activity should be completed in the Ubuntu install from the Software Installation Activity.

In addition, you should have received and accepted the e-mail invitation from GitHub "to collaborate on the github-issues-activity repository."

General Information:

In the following text, commands to be typed at the terminal are shown in mono-spaced type and any parts of those commands that you will need to customize for yourself are shown in angle brackets and <italics>. The angle brackets are not part of the command and should be omitted when you fill in the appropriate values.

Each time you reach a Checkpoint , please stop and wait. These are points at which we will discuss subtleties of the operations and ensure that the class is progressing together. If you reach a checkpoint before other groups, check to see if you might be able to provide assistance.

The slides used during the activity are available for later reference. The titles of the slides illustrating each task correspond to underlined sub-section namess below.

A cheatsheet with a short summary of each of the sets of commands that we use for particular tasks is also available.

Part 1: Before the First Class

In order to allow us to focus on the more interesting and complicated parts of git/GitHub in class you are asked to do some parts of this activity now, before the first class period. You'll also be asked after this class to do some additional work in preparation for the second class period.

Part 2: Hands-On in the First Class

In a common GitHub workflow you will, as you have done, fork a repository (the Upstream repo) into your own GitHub account (your origin repo) and then clone that to your local machine (your Local repo). At that point your local repo, your origin repo and the upstream repo will all be identical. In addition, each of these repositories will have a master branch, which contains the current reference version of the code according to the upstream repository.

In practice you will never edit code on the master branch. Instead, each time you want to work on the code (add a feature, fix a bug, etc) you will create a new feature branch and edit the code there. The feature branch behaves like it is a full copy of the master branch, but git is smart enough to just store the changes you make without making a full copy. In other words, it really just keeps track of the changes that would have to be made to get from the master branch to the version in your feature branch. By editing code on your feature branch, you will be able to leave the master branch in a state that is consistent with the upstream repository. This will be very helpful in integrating changes made by others into your local and origin repositories. It also has the advantage of making it easy to discard changes if you decide they are not working out.

As you work on the feature or bug fix you'll commit changes to the feature branch in your local repo. When you've finished work on the feature or bug fix you'll push your feature branch to your origin and then issue a pull request for that feature branch to the upstream. The manager of the upstream can then merge your changes into the project (most likely after asking for some additional work).

The following steps walk you through the basic process of creating and working on a feature branch, committing changes to your local repository, pushing a feature branch to your origin, creating a pull request and finally bringing your local and origin master branches back into sycnh with the upstream.

Part 3: Before the Second Class

Thus far, the changes you have made and integrated into the project have been carefully selected so that no change you made conflicted with a change made by someone else. This meant that your feature branch was able to be merged into the upstream master automatically. In practice however, it is quite likely that when multiple people are changing code concurrently they will make changes that are in conflict with each other. Complete the steps below before the next class. These steps will have you make a change that will generate conflicts and we will then walk through the process of resolving those conflicts in the next class.

Part 4: Hands-On in the Second Class

Before this class you made changes that fixed a "Round2" issue and generated a pull request to the upstream to merge your results. In practice, while you are working on your fix other contributors will make pull requests and their work will be merged into the upstream. To simulate this, the instructor has made changes to the upstream. These changes have been designed to conflict (i.e. have changes in the same line of code, or changes that cannot be merged automatically). You may have noticed when you created your pull request that GitHub indicated (in red) that it "Can't automatically merge" your pull request. This is GitHub's way of letting you and the upstream project managers know that there is a conflict between the code in the upstream and the edits in your pull request.

When a branch cannot be merged automatically what is typically done is that the person issuing the pull request will be asked to merge the changes from the current upstream master into their feature branch. During this process you will have to resolve the conflicts that exist manually by deciding what the conflicting code should look like in each case. Once the conflicts are resolved, the pull request is updated by pushing your edited feature branch to your origin. The upstream manager will then be able to merge your updated pull request you issued into the upstream.


Acknowledgements: This assignment builds from and adapts ideas and content from the following activities created by others: