Git - Branching Workflows



Depending on how they're used, you can divide branches into two major groups.

  • Long-Running Branches

  • Short-Lived / Topic Branches

Note: This is just a semantic division. Technically (and practically), a branch is just a branch and always works in the same way.

Long-Running Branches

The three-way merge feature in Git makes branch merging easier over time. These branches are used on a higher level, independent of a single feature or bugfix development.

Multiple long-lived branches for various phases of development are frequently maintained by developers. This comprises:

  • A master branch containing code that is reliable and ready for release to production.

  • A develop or next branch which integrates reliable features from temporary branches into continuing testing and development.

These branches typically represent states in your project lifecycler and can remain in your project for a longer time (or even all the time).

git managing workflows

The Workflow includes:

  • Developing features on short-lived topic branches (e.g., auth-module).

  • Merging tested and stable branches into the next or develop branch.

git branching workflows

Branches function as stable silos in a hierarchical structure.

  • After passing tests, commits progress from less stable branches to more stable ones.

  • Some projects integrate less reliable features using additional branches such as proposed updates(pu).

  • Large or complicated projects benefit from managing numerous long-running branches because it preserves stability and controls feature integration.

Topic Branches

Every time you start working on a new feature or bugfix, you should create a new branch for this topic. Such branches are useful for projects of any size since they act as temporary units for particular tasks or features.

Git's efficiency enables for the frequent creation, modification, merging, and deletion of branches during the development process, in contrast to traditional version control systems.

  • Branches allow for distinct growth without affecting with the main source by isolating work.

  • Git's efficient branching model enables quick branch operations, reduces overhead, and integrates seamlessly with various development workflows like GitHub Flow and Gitflow.

  • Branches used in earlier discussions, such as auth-module and bugfix, were deleted after merging into the main branch.

  • This method divides the work into topic-specific branches and enables quick context change.

  • It makes it simpler to review changes and improves understanding of how they affect the codebase.

Following diagram explains this:

After starting on the master branch, developers branch off to work on specific tasks (like task A).

They might make branches similar to taskA-v2 to test out different approaches.

git branching workflows

It is typical to go back to the master branch and complete more work there.

Additionally, developers make experimental branches like exploratory.

This process generates a commit history that describes the history and purpose of every branch in detail.

git branching workflows

The above diagram illustrates the branching process, and some following points are observed as below:

  • taskA-v2 is found to be the best option after evaluation, and exploratory turns out to be surprisingly beneficial based on feedback from colleagues.

  • It is safe to abandon the original taskA branch along with commits C5 and C6.

  • Exploratory and taskA-v2 can be easily integrated into the main branch.

  • This flexible strategy guarantees efficient handling of modifications, irrespective of their temporal sequence.

Advertisements