Skip to main content

Branches - Gitflow

Main and dev

For starters: Do as I say and not as I do.

I say this because I myself have forgot to use separate branches. It is really easy to forget and you will only notice it when it becomes a pain in the ass to fix.

Ok let's start this guide!

Separate branches are a must if you want to step up your git game. It will help you and others.
Here are the rules for it:

Main should always be "bug free". Meaning, it should just work without any major problem.
Dev should be used as a testing ground for new features. Meaning, it can have problem.
Feature/<feature-name> should be used to develop feature in an isolated matter and later be merged into dev.

Depending on what workflow you want to use the names and rules can slightly vary.


The use of feature branches

Feature branches will help you develop faster and more time efficiently. The main reason for that is that you don't need to deal with the commits of other developer because your feature branch is isolated from dev.


Protected branches

You should always protect your main branch!

Protecting main as a number of advantages.

  1. Less chances of breaking main
  2. Requiring code reviews which can lead to finding bugs
  3. etc

If you are working alone this will not really help you other than protect you from yourself.

If you are working in a team then this is a must.

The protection rule I use are as following:

  1. Require a pull request before merging
  2. Require approvals (Amount depends on team size) (Not really needed for dev)
  3. Do not allow bypassing the above settings

Those rules can also be used for dev branches.


Other resources to look at

https://www.gitkraken.com/learn/git/git-flow (Last accessed 22.03.2023)

https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow (Last accessed 22.03.2023)