Introduction to Branching
Why Branching?
This section will teach the user to use a feature known as branching to manage multiple parallel "copies" of the codebase by guiding them through steps of a tutorial. It will also explain how using branches can improve project organization when there is a large codebase with lots of independent work being done on it.
Problem Statement
Because pulling and pushing code to one revision log requires synchronization (local repo must be up to date before pushing, other developers can push conflicting code - that which modified other code your work is based on), working with a singular log of revisions becomes difficult. This is true even when different coders are working on unrelated pieces of code, which leads to inefficiency when developers want to work asynchronously and are constantly creating conflicts. Developers need a tool to work asynchronously on the same codebase by deferring conflicts/inconsistencies in their changes to a time of their choice later.
Background: Managing Complex Codebases
In more complex projects, Git is not only used as a revision control tool, but also an organizational tool for when development is happening in multiple places, across different sub-teams, at the same time.
Git addresses this problem through a feature known as branching. Branching allows developers to take copies of a set of revisions (thus creating a branch), and work on them separately, committing different code to copies of the codebase. Then, through a process called merging, the additions in each branch can be combined later, thus avoiding workflow interruptions from conflicts along the way.
Allowing developers to defer/avoid code conflicts that interrupt their workflow when working independently is not the only benefit; Branching opens the doors for a wide variety of practices that create a more organized and reliable codebase. For example, branches allow developers to:
Code independently based on the same codebase, without conflicts caused by being forced to pull each other’s potentially unrelated work
Store experimental or buggy code somewhere else for testing purposes, but still tracked by revision control
Group independent changes by feature to keep different pieces of work-in-progress code organized without interfering bugs/issues across different sub-projects
These are the benefits we hope you can leverage after learning to use branches in Git.
Constraints
Branching and merging are features are built into Git so there are no limitations in terms of using them.
Scope
This section focuses on branching and branching-related features. There are other features for codebase management and branch management such as rebasing and submodules, but branching is the most commonly used, and other the other features are quite advanced and have many pitfalls. Understanding branching and merging is sufficient for being able to manage complex codebases, as they already allow for asynchronous development and combination of code. Because teaching this kind of codebase management is the purpose of the document, and because this section is intended as a beginner-level tutorial, rebasing, submodules, and other features are not within the scope of this document.
Last updated
Was this helpful?