---
# System prepended metadata

title: branching
tags: [git, notes]

---

---
title: branching
tags: git,notes
---

Branching
===

Branching is essentially like grouping commits together, thereby allowing us to undo or revert an applied changes to a permanent branch by reverting the merge commit.


Classification of branches
---
In our usage of branching, branches are classified into two categories 

![](https://i.imgur.com/mbAMh59.png)

:::info
:bulb: In every code repository the permament branches should be existing and created right away
:::


### Table of branches

| type     | naming           | branch from      | merged to | delete   |
| -------- | --------         | --------         | --------  | -------- |
| master   | master           | null             | null      | no       |
| develop  | develop          | master           | master    | no       |
| feature  | feature/{name}   | develop          | develop   | yes      |
| bug      | bug/{ref}        | develop          | develop   | yes      |
| release  | release/v{x.y.z} | develop          | develop   | yes      |
| hotfix   | hotfix | master  | master & develop | yes       | yes      |

**Definition:**
- **type** refers to the type of branch
- **naming** pattern of the branch
- **branch from** refers to the branch it would created from
- **merged To** refers to the branch it merges onto
- **delete** determines if must be deleted after being merged / pull requested merged

**Purpose of each branches:**
{%hackmd thRxXoyFRVOkg6jCf8wzVw %}

:::info
:bulb: Bug fixes and hot fixes are different.
- **Bug fixes** are for development issue and follows release cycle
- **Hot fixes** are for production issue and are immediately release
:::
     

##### Branch Protection rule
The master branch should atleast configured with either of the following protection rules:
- **Status Checks**
    commits must first be pushed to another branch, then merged or pushed directly to a branch that matches this rule after status checks have passed.
- **Pull Request Review** 
    all commits must be made to a non-protected branch and submitted via a pull request with the required number of approving reviews and no changes requested before it can be merged into a branch 
    
Both protection rules prevent contributors to push to remote branch directly and requires merge process to be done in order to update the branch.

:::info 
:bulb: Naming pattern is useful when branch protection rule applies to a pattern
:::

:::warning
:exclamation: In every code repository a branch protection rule must be applied to master branch

If you noticed the repository has no branch protection rule, informed the lead of the project immediately to apply protection rule
:::