Purpose
Git is the de facto version control system. Most of us use Git every day; our client work involves interacting with, and ultimately delivering, git repositories to our clients.
Git is a powerful tool. This lesson goes through some of the basics, but we recommend that you continue to explore its most advanced features as you use it. We also recommend that you use the command-line git interface, at least to start.
Why use Git? First, it acts as a simple backup, reducing the chances of losing code. It allows multiple developers to edit the code simultaneously and merge their changes (mostly) seamlessly. It lets us write documentation (in commit messages) tied to the state of the code when we wrote it. It lets us roll back to previous versions of the code easily. Git branches let us work on several copies of the code simultaneously, letting us remain flexible to try new approaches and test proofs of concept. There are a host of other benefits too, some of which you will explore in the exercises.
Learning Material
Basics
- What is version control?
- How to install git
- All of the “Getting Started” tutorials
- Other sections may be helpful as well; you can safely ignore references to Bitbucket which is Atlassian’s competitor for GitHub, which we typically use.
- Learn Git Branching, an interactive exploration of common Git workflows.
Commit Messages
The git log
command can be a powerful tool to understand changes in a repository, but as with many things, “garbage in, garbage out” applies. Writing concise, descriptive commit messages will help your colleagues and your future self quickly identify the context surrounding changes. Conversely, writing commit messages like fix bug
or new feature
will force the reader to perform a line-by-line comparison, all without the background context the original author had.
Exercises
To learn as much as possible from these exercises, write your responses before revealing the provided answers. If any exercises seem irrelevant, you can skip them and instead write a justification as to why they are unimportant. These justifications will help us improve the lesson for future employees.
Exercise 1
Install git and ssh. Create a GitHub account if you don’t already have one. Create an SSH key and add it to your GitHub account. Create a private repository in your GitHub account with a README. Clone it using ssh (this means you shouldn’t need to enter your github password).
Exercise 2
Clone a copy of our DICOM Standard git repository. Use the git blame
command to see who has last edited the README for that project.
Exercise 3
Use git to find the oldest commit that includes the word “TODO” in the commit message.