Chapter 3. Branches

A branch allows the user to launch a separate line of development within a software project. When you create a branch, you are creating a fork from a specific state of the project’s timeline. This allows development to progress in multiple directions simultaneously. Think of it as time travel, where you have the ability to create alternate parallel timelines from a single starting point. A branch also gives you the ability to create different versions of a project. Often, a branch can be reconciled and merged with other branches to combine divergent efforts.

Creating branches in Git is considered a lightweight and inexpensive operation. This is because a branch is just a pointer to a specific commit object in a Git repository. Git allows many branches, and thus many different lines of development within a repository can exist simultaneously at any given moment. Moreover, Git has first-rate support for merges between branches. As a result, most Git users make routine use of branches and are naturally encouraged to do so frequently.

In this chapter, we will take a top-down approach to thinking about how branches function in Git by looking at how developers maintain multiple lines of development within a project. The concept discussed in this chapter will complement the key takeaways we learned in Chapter 2.

We will show you how to list, view, select, create, and discard branches. We will also provide some best practices so that your branches don’t disrupt ...

Get Version Control with Git, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.