04 Prepare : Reading
Version Control with GitHub
Objectives
Learn how version control is used in software development.
Learn how to use the git version control system.
Learn how to use GitHub to share code.
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:
-
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
-
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.
-
Sally's next step is to
add
the PositronicBrain.java file to the list of changed files to commit.git add PositronicBrain.java
-
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."
-
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
-
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:
-
Go to GitHub's Student Developer Pack site and sign up for an account.
-
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.
-
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.