Diagrams / Mermaid Git Graph: Syntax & Examples
Mermaid Git Graph: Syntax & Examples
Learn Mermaid Git graph syntax for commits, branches and merges. Follow an example history and distinguish the diagram from real Git operations.
When to use Git Graph
Explain branch history with a Mermaid Git graph. A compact graph can show a feature branch, a release strategy, or a merge sequence more clearly than a long paragraph of commands. Keep it focused on the commits needed for the explanation.
Read the Git Graph example
Diagram source
gitGraph
commit id: "docs"
branch examples
checkout examples
commit id: "flowchart"
commit id: "png"
checkout main
merge examples
commit id: "publish"How to use this tool
- Start with the example in the editor and identify the elements that answer your question.
- Replace the sample labels and values, previewing after each structural change.
- Review the diagram at its intended reading size, then keep the source and export the format your document accepts.
Syntax and interpretation
| Concept | How to apply it |
|---|---|
| Commits | Each commit is a modeled operation. IDs make it easier to discuss particular points in the history. |
| Branch operations | Create a branch before checking it out. Merge into the intended current branch. |
| Renderer boundary | gitGraph support does not make the renderer a Git implementation. Layout and supported syntax can vary between hosts. |
Common questions
Will this change my repository?
No. The editor renders text. It neither runs Git commands nor checks whether a real merge would succeed without conflicts.