CS 257: Software Design

Lab: git branches

In class. Nothing to hand in.

In this lab, you'll learn about git branches, merging, and branch deletion. These concepts should put you on the road to making git a powerful collaboration tool rather than a mysterious source of confusion and pain.

A little advice

Take your time with this lab. There's no hurry. Go slow, and take a look around after every operation. Keep your eyes open for changes and confusing bits. Keep a list of questions and ask more than one person for their answers. You're after an understanding of how git works, and that takes time, experimentation, and a fair amount of puzzlement before understanding arrives.

Resources

Here are a few tutorials and references that I have found useful as I have learned about branching, etc.

One handy command: viewing your commit graph

When I'm working on a project that branches frequently (typically because I'm working with at least two or three other people), I find it very helpful to be able to see the "commit graph"—that is, a diagram of the commits, branches, merges, etc. One way to get a pretty clean picture of the commit graph is:

git log --all --graph --decorate --oneline

This generates a display that looks like this:

You can create an alias for this command and put it in the .gitconfig file in your home directory (works in any Unix environment, including Windows bash):

[alias] graph = log --all --graph --decorate --oneline

which lets you do just "git graph" to get the cool diagram.

Setup: two clones of the repository

You're going to have two separate clones of your repository, and we'll call the people manipulating those two clones Alice and Bob. It might be that Alice is using one computer and Bob is using a different computer, or it might be that you're all alone and have two separate terminal windows open, so you're playing the role of both Alice and Bob. Here's how to get started.

Experiment 1: Merging without branches

Experiment 1.5: git checkout

Alice, with everybody watching and discussing

Experiment 2: Merging without branches, but with a merge conflict

Don't forget: make sure Alice's and Bob's clones are both in the same state before moving on.

Experiment 3: Branching

Experiment 4: Merging a branch

Experiment 5: Deleting a branch

This is pretty involved. You have to make sure that both Alice and Bob agree that the goat branch needs to be deleted, and it has to be explicitly deleted in Bob's clone, Alice's clone, and the remote repository (GitHub, in this case).

There's a great Stack Overflow post about git branch deletion that's worth reading. The steps listed below come in part from this post.

A simple github workflow and pull requests

Coming soon in a separate lab...