liveBook · Manning

Branch

As explained in Software Engineering for Data Scientists

A branch is a named line of development in a version-control repository that can receive changes independently of other lines.

A branch is a separate snapshot, or copy, of a repository that lets work continue independently from the main line. Use one when a data science project needs to test an idea without changing the code treated as the source of truth. section 2.5 section 2.3.1

Branches keep experiments separate from production-ready code. A small project with few contributors may use only main, while a larger team can use branches to prevent rapidly changing prototype code from cluttering main. section 2.3.1 section 2.5

A practical Git branch workflow is:

  • List local branches with `git branch`; the asterisk marks the active branch. Add `-a` to include remote branches. section 2.5.1
  • Create an experimental line with `git branch rules_based_model`, then switch to it with `git checkout rules_based_model`. section 2.5.1
  • Commit work on the active branch; those commits affect that branch rather than main. section 2.5.1
  • Publish a newly created branch with `git push --set-upstream origin rules_based_model`. section 2.5.1
  • When the work is ready, switch to main and merge it with `git merge rules_based_model`. section 2.5.1

Compare churn-model approaches safely

One collaborator can develop a rules-based churn model on one branch while another tests a random forest on another. If the random forest is chosen, merge that branch into main; the unselected experiment need not change the main codebase. section 2.4.3 section 2.5.1

Figure 2.7 Branching can be thought of as having different snapshots of the same codebase. Each branch might have its own alternate set of changes. However, each branch can ultimately be merged back together, or back into the single main branch.
ch2 branching overview

The diagram visualizes branches as alternate snapshots that can later merge back into a single main branch. section 2.5

Agree on a branch policy with contributors early. Clear expectations about which work belongs on main versus experimental or development branches make collaboration and code tracking easier. section 2.7 section 2.6

How Software Engineering for Data Scientists covers it

How deep it goes
Demonstrates listing, creating, switching, publishing, and merging branches, with branch-policy tradeoffs for different team contexts.
Examples
Uses competing rules-based and random-forest customer-churn models, plus a rules_based_model branch and churn script.
What it assumes
Assumes a Git repository and introduces branch operations through direct terminal commands.
What you can do after
Operate/configure it by creating, switching, publishing, and merging Git branches around experimental code.
How it connects
Connects branches to Git, repositories, commits, remote repositories, main branches, and git merge.

Also explained in

Compare how 7 books explain branch →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Engineering for Data Scientists. The section links point to the parts of the book it draws on.