Mermaid code
gitGraph
commit id: "v1.0"
branch develop
checkout develop
commit id: "setup"
branch feature/search
checkout feature/search
commit id: "search api"
commit id: "search ui"
checkout develop
merge feature/search
branch release/1.1
checkout release/1.1
commit id: "bump 1.1"
checkout main
merge release/1.1 tag: "v1.1"
checkout develop
merge release/1.1
checkout main
branch hotfix/login
commit id: "fix login"
checkout main
merge hotfix/login tag: "v1.1.1" Paste this into any tool that renders Mermaid, or into the editor to change the theme and export PNG or SVG. Syntax reference: Git Graph guide.
What this diagram shows
This graph follows a classic release-branch model. develop carries day-to-day work. feature/search branches from it and merges back. release/1.1 is cut from develop, receives a version bump, and merges into main with a v1.1 tag and back into develop. The hotfix/login branch comes off main and merges back with a v1.1.1 tag.
Mermaid draws the graph from the sequence of commit, branch, checkout, and merge commands, so the source reads like a shell history. That makes it easy to keep in a CONTRIBUTING file next to the written rules.
How to adapt it
- For trunk-based development, delete the
developandrelease/1.1lines and branch every feature directly frommain. - Rename
feature/searchandhotfix/loginto your branch naming convention, for examplefeat/JIRA-123. - Add
tag: "..."to any merge intomainthat produces a deployable version. - Insert more
commit id: "..."lines ondevelopbetween merges to show that other work landed in parallel. - Add
%%{init: {"gitGraph": {"mainBranchName": "master"}}}%%on the first line if your default branch is not called main.
FAQ
Why does the hotfix merge into main but not back into develop here?
To keep the example short. In practice add checkout develop and merge hotfix/login after the main merge, otherwise the fix is lost at the next release. Most branching models require that back-merge.
Can I control which commit a branch starts from?
A branch command always starts from the current checked-out commit. Run checkout on the branch you want as the parent first, then branch. There is no way to branch from an older commit retroactively.
How do I show a squash merge or a cherry-pick?
Use merge feature/search type: HIGHLIGHT to emphasize a merge, and cherry-pick id: "search ui" to copy a commit onto the current branch. Both need the referenced commit ids to exist.