CS 272 Software Development

CS 272-01, CS 272-02 • Fall 2022

Using Branches

Using branches in git will be extremely helpful for both homework and projects in this class. It will also come in handy outside of class; branching is used heavily in any major software development project.

What is Branching?

Git Branching

The way git tracks history is using a directed acyclic graph (DAG), which is a graph with arrows but no cycles (similar to a tree). You can think of branching as a label or pointer to a specific branch (or path) in this graph.

Still confused? Essentially, branching creates a new line of development that allows you to work on new features without disturbing other branches (like the main or other stable production branches). It is essentially a copy of your code made at a specific point in time. That branch (or copy) can then be merged back into other branches when that new feature is stable.

There are several guides (linked below) that explain this concept further.

When Should You Branch?

All grading and code reviews will be done from your main branch. Use a branch any time you want to work ahead or try something out without affecting how your code will be graded. This includes:

  • Create a branch before working on homework after the deadline. This prevents the timestamp on the main branch from changing, which will trigger a late submission penalty. If you manage to get new tests passing in that branch, then it may be worthwhile to merge those changes back into main even if it does trigger the late penalty.

  • Create a branch before working ahead on projects. You may not include code in your main branch from future projects until you have fully passed code review. You are still able to make releases from other branches, so this allows you to still work ahead and pass functionality without disturbing the code review process.

In general, it is a good idea to always use branches for development and keep only stable, tested, production-ready code in the main branch.

Traditionally, the primary branch of a git repository was the master branch. There is a fantastic movement to move away from this and other troubling terminology prevalent in CS and tech. GitHub now automatically uses main as the default, but you may find older repositories still using master as the primary branch.

How Should You Branch?

Learning both the command-line and the Eclipse interface is recommended. Learning the commands to branch and merge helps with understanding, and learning to perform those commands within the Eclipse interface helps avoid the amount of switching in/out of the application necessary during a normal workflow.

Here are a few guides on the topic,

Once you start branching, it is likely you will run into merge conflicts.

Paragraph-based prototype – rough visualization of the functionality.png
By Johanna Strodt (WMDE) - Own work, CC BY-SA 4.0, Link

There are several guides dedicated to resolving these conflicts:

Do not get discouraged! Dealing with a merge conflict (or other repository issue) is like a rite-of-passage for software developers. It is frustrating for everyone! (There are many jokes/comics/memes on this topic that are not necessarily appropriate to share in a classroom setting.)