Branches and Branching Strategies

9 min

Table of contents


1 — Why branches?

A branch is an independent line of development. It lets you work on a new feature or a fix without touching the stable code that others use.

Think of a branch as a separate draft. You can try anything you want; as long as you have not merged, other people's work is not affected.

Without branches, the whole team would write in the same file at the same time: guaranteed chaos. With branches, each person advances in their own lane, then you bring everything together cleanly.

The basic commands already seen in module 01:

bash
# Create a branch and switch to it
git switch -c feature/login

# List branches
git branch

# Return to main
git switch main
ActionModern commandOlder syntax
Create + switchgit switch -c namegit checkout -b name
Switchgit switch namegit checkout name
Listgit branchgit branch
Deletegit branch -d namegit branch -d name

🔧 Mini-exercise — Write the modern command to create a feature/login branch and switch to it in one step.

✅ See a solution

git switch -c feature/login (equivalent to the older syntax git checkout -b feature/login).

↑ Back to top


2 — Branch types

In a team, you do not create branches at random: you give them a role and a conventional name. Here are the most common types.

Branch typeUsual prefixRoleLifetime
Mainmain (or master)Production code, always stablePermanent
IntegrationdevelopGathers features in progressPermanent
Featurefeature/Develop a new featureShort
Releaserelease/Stabilize before a production releaseShort
Urgent fixhotfix/Fix a critical production bugVery short

Realistic name examples:

bash
feature/ajout-paiement-stripe
feature/dashboard-utilisateur
release/1.4.0
hotfix/correction-faille-login

A good naming convention is free documentation: from the branch name alone, the team knows what it is about.

🔧 Mini-exercise — You must urgently fix a login vulnerability in production. Which branch prefix do you use, and propose a full name.

✅ See a solution

The hotfix/ prefix (urgent fix starting from main). Example: hotfix/correction-faille-login.

↑ Back to top


3 — Git Flow

Git Flow is a structured strategy introduced by Vincent Driessen in 2010. It rests on two permanent branches (main and develop) and three types of temporary branches (feature, release, hotfix).

The typical cycle:

  1. You start from develop to create a feature/* branch.
  2. Once finished, the feature is merged into develop.
  3. When enough features are ready, you create a release/* to stabilize.
  4. The release is merged into main (and tagged) and into develop.
  5. A critical production bug? You create a hotfix/* from main, then merge it into main and develop.
bash
# Start a feature (without the git-flow extension)
git switch develop
git switch -c feature/panier

# ... work + commits ...

git switch develop
git merge feature/panier
git branch -d feature/panier
AdvantagesDrawbacks
Very structured, clear rolesHeavy, many branches
Ideal for planned versionsPoorly suited to continuous deployment
Clearly separates dev and prodComplex merges, conflict risk

Git Flow shines for software shipped by versions (mobile apps, installed software). For a website deployed 10 times a day, it becomes a brake.

↑ Back to top


4 — GitHub Flow

GitHub Flow is a simple and light strategy, designed for continuous deployment. A single permanent branch: main. Everything else goes through short feature branches and pull requests.

The golden rules:

  1. main is always deployable.
  2. For any work, you create a descriptive branch from main.
  3. You commit regularly and open a pull request (seen in lesson 03).
  4. After review and green tests, you merge into main.
  5. You deploy main immediately.
bash
git switch main
git pull
git switch -c feature/filtre-recherche
# ... commits ...
git push -u origin feature/filtre-recherche
# → open a Pull Request on GitHub
AdvantagesDrawbacks
Simple, few branchesAssumes good test coverage
Perfect for web / SaaSLess suited to multiple versions to maintain
Favors small frequent releasesRequires discipline on the quality of main

GitHub Flow is probably the best starting point for a modern team: enough structure to collaborate, enough lightness to go fast.

🔧 Mini-exercise — In GitHub Flow, write the two commands to start from an up-to-date main before creating your working branch.

✅ See a solution
bash
git switch main
git pull

Only then: git switch -c feature/....

↑ Back to top


5 — Trunk-Based Development

Trunk-Based Development pushes simplicity even further: everyone integrates their work into a single branch (the trunk, that is main) very frequently — ideally several times a day.

Key principles:

  • Feature branches are tiny and live less than a day.
  • Unfinished features are hidden behind feature flags rather than in long-lived branches.
  • Continuous integration (CI) is mandatory: every commit triggers build + tests.
bash
# Ultra-short cycle
git switch main
git pull
# small change...
git commit -am "Add the export button"
git push      # integrated into the trunk a few minutes later
AdvantagesDrawbacks
True continuous integrationRequires a solid, fast CI
Avoids “merge hell”Requires a lot of discipline
Practice of very high-performing teams (Google, etc.)Feature flags to manage

The worst enemy of Git teams is branches that live for weeks. The later you integrate, the more painful the merge. Trunk-based solves that by integrating early and often.

🔧 Mini-exercise — In Trunk-Based, how do you integrate an unfinished feature without blocking others or creating a long-lived branch?

✅ See a solution

You hide the unfinished code behind a feature flag: it is integrated into the trunk but disabled for users.

↑ Back to top


6 — Compare and choose a strategy

There is no universal strategy: the right choice depends on the product type, the team maturity, and the deployment frequency.

CriterionGit FlowGitHub FlowTrunk-Based
Permanent branches2 (main + develop)1 (main)1 (main)
ComplexityHighLowVery low
Delivery frequencyBy versionsContinuousVery continuous
Branch lifetimeLongShortVery short (< 1 day)
Automated tests requiredDesirableImportantIndispensable
Ideal caseVersioned apps, mobileWeb / SaaS, mid-size teamMature team, strong CI

Advice: most teams should start with GitHub Flow. It offers the best simplicity / safety trade-off. You migrate to trunk-based when CI is mature, or to Git Flow only if the product requires versions.

↑ Back to top


7 — Quiz — Branching strategies

Question 1: What is a Git branch mainly for?

a) Backing up the repository to the cloud

b) Working in isolation without affecting the stable code

c) Compressing files

d) Deleting the history

See the solution

Answer: b) — A branch is an independent line of development that isolates the work until the merge.


Question 2: How many permanent branches does Git Flow use?

a) A single one (main)

b) Two (main and develop)

c) None

d) One per developer

See the solution

Answer: b) — Git Flow rests on two permanent branches: main (production) and develop (integration).


Question 3: Which strategy is best suited to a website deployed several times a day?

a) Git Flow

b) GitHub Flow or Trunk-Based

c) No branch at all

d) One branch per year

See the solution

Answer: b) — GitHub Flow (and even more so Trunk-Based) are designed for continuous deployment. Git Flow would be too heavy.


Question 4: In Trunk-Based Development, how do you hide an unfinished feature?

a) In a long-lived branch of several weeks

b) With a feature flag

c) By deleting the code every evening

d) You cannot, you must finish everything at once

See the solution

Answer: b) — Feature flags let you integrate unfinished code without enabling it for users, avoiding long-lived branches.


Question 5: Which branch prefix do you use to fix a critical bug directly in production?

a) feature/

b) release/

c) hotfix/

d) develop/

See the solution

Answer: c) — A hotfix/ branch starts from main to fix an urgent bug, then is merged into main and develop.

↑ Back to top


8 — Practice — Set up GitHub Flow

Instructions

You work on a repository whose main is stable. You are asked to add an “About” page. Implement GitHub Flow:

  1. Start from an up-to-date main.
  2. Create a well-named feature branch.
  3. Make a commit that adds the file apropos.html.
  4. Push the branch to the remote repository to prepare a pull request.
  5. List your branches to verify.

Correction

bash
# 1. Start from an up-to-date main
git switch main
git pull origin main

# 2. Create a descriptive branch
git switch -c feature/page-apropos

# 3. Create the file then commit it
echo "<h1>About</h1>" > apropos.html
git add apropos.html
git commit -m "Add the About page"

# 4. Push the branch to the remote
git push -u origin feature/page-apropos

# 5. Check the branches
git branch

Expected result:

StepVerification
Branch createdgit branch shows * feature/page-apropos
Commit presentgit log --oneline -1 shows “Add the About page”
Branch pushedGit shows * [new branch] feature/page-apropos -> feature/page-apropos
Tracking configured-u links the local branch to the remote branch
text
* feature/page-apropos
  main

Logical next step: open a pull request on GitHub to have this work reviewed and merged — that is exactly the subject of lesson 03.

↑ Back to top


9 — Summary

Key takeaways

  1. A branch isolates work without affecting the stable code.
  2. Branch types: main, develop, feature/, release/, hotfix/ — each with a role.
  3. Git Flow: structured, two permanent branches, ideal for planned versions.
  4. GitHub Flow: simple, one main branch + pull requests, perfect for the web.
  5. Trunk-Based: very frequent integration on the trunk, requires a solid CI.
  6. The choice depends on the product, the team, and the deployment frequency.

What's next

Now that you know how to organize your branches, on to lesson 02 — Merge and rebase: how to bring these branches together cleanly and resolve conflicts.

↑ Back to top


All rights reserved. Any reproduction, distribution, use or adaptation of this course, in whole or in part, is strictly prohibited without the prior written authorization of Dr. Haythem REHOUMA.

Course created by Dr. Haythem REHOUMA — Development and Deployment of Data Solutions