Software Design and Development :: CS 246

04 Prepare : Reading

Version Control with GitHub

Objectives

Software Design Principle

Use a version control system.

Version control systems (VCS) allow developers to maintain a record of how their code has changed over time. When used properly, a VCS can help a developer track down the exact point in time when a bug was introduced or fixed, easily undo changes, and collaborate with other developers.

There are many types of version control systems. Some of the more popular ones include CVS, subversion, mercurial, and git. In recent years, git has quickly become the most popular of the group.

Git

Git stores files in a type of database called a repository. Most software teams that work with git keep a central repository on a server somewhere that everyone on the team can access. This repository not only stores the files, but also the history of every change made to each file, including who made the changes and when those changes were made.

Git works with groups of changes called commits. A single commit might have many changes associated with it. Those changes might include updates to existing files, the addition of new files, or the removal of files.

Imagine a developer named Sally who has started a new job for US Robotics. She's told that her first assignment is to fix a bug in the positronic brain code that is causing all of the robots to walk around in circles. She takes the following steps:

  1. First, Sally will clone the central repository. (Note that this is not a real GitHub repository link for robotics but is shown here as an example.) This creates a copy of the repository on her computer.

    git clone https://github.com/us-robotics/brain.git
    
  2. Next, Sally finds the bug in the PositronicBrain.java file that is causing the odd behavior. She quickly fixes the bug and saves her changes.

  3. Sally's next step is to add the PositronicBrain.java file to the list of changed files to commit.

    git add PositronicBrain.java
    
  4. When Sally is done adding files, she will commit those changes, adding a brief message to describe her changes.

    git commit -m "Fixed the bug that made robots attack ice cream shops."
    
  5. Now that her own changes are finished, before she can share them, she must pull any changes her teammates have made from the central repository into her local copy.

    git pull
    
  6. After making sure that there isn't a conflict between her teammates' changes and her own, she is ready to push her changes up to the central repository.

    git push
    

Most of your interactions with a git repository will follow the same six steps that Sally followed. Note the sequence of the pull and push commands.

This is critical when working with git: Always pull before you push.

Additional Reading

Please read the following:

GitHub

One of the reasons that git is so popular is because of GitHub. GitHub is a site that provides repository hosting. You can sign up for a free acount and host public repositories that anyone can have access to, or you can sign up for a paid account, which allows you to have private repositories that only you and your team have access to.

By using github as the central repository, teams can collaborate all over the world, keeping their code in sync easily.

Preparation Assignment

In order to interact with a git repository, you need to have the git software tools installed on your computer. In addition, you will need to sign up for an account on GitHub. While anyone can sign up for a free account, as a student you can get a student account for free, which allows you to also have private repositories.

Before Class, complete the following:

  1. Go to GitHub's Student Developer Pack site and sign up for an account.

  2. Next, follow steps 1 - 6 of this guide to create your first repository on GitHub. You do not need to import anything into the repository at this time.

  3. Follow the steps outlined here to download and configure git on your computer.

Reading Quiz

Don't forget to take the Reading Quiz in I-Learn. This quiz can be taken as many times as you like, but you must score at least 90% to pass. If you fail the quiz, review the relevant parts of the reading and try again.

As before, one of the quiz questions is a "deep thought" question whose answer won't come directly from the reading.