| # | Section |
|---|---|
| 1 | Why branches? |
| 2 | Branch types |
| 3 | Git Flow |
| 4 | GitHub Flow |
| 5 | Trunk-Based Development |
| 6 | Compare and choose a strategy |
| 7 | Quiz — Branching strategies |
| 8 | Practice — Set up GitHub Flow |
| 9 | Summary |
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:
# Create a branch and switch to it
git switch -c feature/login
# List branches
git branch
# Return to main
git switch main| Action | Modern command | Older syntax |
|---|---|---|
| Create + switch | git switch -c name | git checkout -b name |
| Switch | git switch name | git checkout name |
| List | git branch | git branch |
| Delete | git branch -d name | git branch -d name |
🔧 Mini-exercise — Write the modern command to create a feature/login branch and switch to it in one step.
git switch -c feature/login (equivalent to the older syntax git checkout -b feature/login).
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 type | Usual prefix | Role | Lifetime |
|---|---|---|---|
| Main | main (or master) | Production code, always stable | Permanent |
| Integration | develop | Gathers features in progress | Permanent |
| Feature | feature/ | Develop a new feature | Short |
| Release | release/ | Stabilize before a production release | Short |
| Urgent fix | hotfix/ | Fix a critical production bug | Very short |
Realistic name examples:
feature/ajout-paiement-stripe
feature/dashboard-utilisateur
release/1.4.0
hotfix/correction-faille-loginA 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.
The hotfix/ prefix (urgent fix starting from main). Example: hotfix/correction-faille-login.
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:
develop to create a feature/* branch.feature is merged into develop.release/* to stabilize.release is merged into main (and tagged) and into develop.hotfix/* from main, then merge it into main and develop.# 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| Advantages | Drawbacks |
|---|---|
| Very structured, clear roles | Heavy, many branches |
| Ideal for planned versions | Poorly suited to continuous deployment |
| Clearly separates dev and prod | Complex 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.
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:
main is always deployable.main.main.main immediately.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| Advantages | Drawbacks |
|---|---|
| Simple, few branches | Assumes good test coverage |
| Perfect for web / SaaS | Less suited to multiple versions to maintain |
| Favors small frequent releases | Requires 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.
git switch main
git pullOnly then: git switch -c feature/....
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:
# 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| Advantages | Drawbacks |
|---|---|
| True continuous integration | Requires 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?
You hide the unfinished code behind a feature flag: it is integrated into the trunk but disabled for users.
There is no universal strategy: the right choice depends on the product type, the team maturity, and the deployment frequency.
| Criterion | Git Flow | GitHub Flow | Trunk-Based |
|---|---|---|---|
| Permanent branches | 2 (main + develop) | 1 (main) | 1 (main) |
| Complexity | High | Low | Very low |
| Delivery frequency | By versions | Continuous | Very continuous |
| Branch lifetime | Long | Short | Very short (< 1 day) |
| Automated tests required | Desirable | Important | Indispensable |
| Ideal case | Versioned apps, mobile | Web / SaaS, mid-size team | Mature 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.
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
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
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
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
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/
Answer: c) — A hotfix/ branch starts from main to fix an urgent bug, then is merged into main and develop.
You work on a repository whose main is stable. You are asked to add an “About” page. Implement GitHub Flow:
main.apropos.html.# 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 branchExpected result:
| Step | Verification |
|---|---|
| Branch created | git branch shows * feature/page-apropos |
| Commit present | git log --oneline -1 shows “Add the About page” |
| Branch pushed | Git shows * [new branch] feature/page-apropos -> feature/page-apropos |
| Tracking configured | -u links the local branch to the remote branch |
* feature/page-apropos
mainLogical next step: open a pull request on GitHub to have this work reviewed and merged — that is exactly the subject of lesson 03.
main, develop, feature/, release/, hotfix/ — each with a role.main branch + pull requests, perfect for the web.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.
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