Help with Branches (Module 2.3)

(Sarah Dukes) #1


I have a few questions about branches (Module 2.3). I understand how to create new branches but have some questions.

  1. In the video git branch was used in the terminal and git checkout -b and git checkout were used in Git Visualization. What is the difference between these two commands? When would you use one instead of the other?

  2. I have watched the video 3 times and I am still unsure of the purpose of creating a new branch. I understand they are bookmarks to a commit - is it just to make it easier to get back to that specific commit?

  3. In the example in the video where there are two branches extending(?) planets, I don’t understand what this represents in terms of workflow. Does it mean the commits in the two new branches build on the code/information in the Planets branch?

  4. I’ve looked through the thread with solutions that others have posted for Module 2 Exercise 2, but I’m having difficulty making the connection between what was explained in the video and any of my assignments (I teach high school computer science). Most people have posted the workflow without details of the assignment so I am not sure what most of them are showing. Are there examples somewhere with specific assignments/activities and the associated workflow visualization?

(Alexander L. Hayes) #2

I’ll try and answer these. Some come down to personal preference so feel free to follow up!

  1. Each of these commands do slightly different things:
  • git branch is for creating, listing, or deleting branches. By default, running git branch lists the branches for your repository.
  • git checkout [branch-name] switches to an existing branch once it has been created.
  • git checkout -b [branch-name] creates a branch and switches to it. This is a shortcut that combines the previous two commands, using it is the same as running git branch [branch-name]; git checkout [branch-name]
  1. The answer to “what are branches for” is kind of tricky, and really comes down to your personal workflow or the workflow of the group you are working with. I like to use branches to help me focus on specific features, kind of like a todo list (documentation, or unit tests, or adding a new feature to the commandline). Branches can also be useful for working on in-progress things: perhaps a feature that would break the code but you want to keep track of incremental progress before merging with the main codebase.

  2. I think “build[ing] on the code/information in the Planets branch” is a good interpretation. To tie it back to software: there may be a base class on the main branch, but that base class is extended on other branches.

  3. I didn’t have a ready-to-go assignment, so I used an example where students would work together to write a poem. This would be like a group of students working on non-overlapping code: perhaps one student answers a question about finding substrings, and another student answers a question about solving math problems, but they merge their code to submit a single assignment.