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"
The examples branch starts from main, receives commits, and merges back. Checkout changes the branch that receives subsequent commits. Operation order matters even when the final image looks like a simple fork and join.

How to use this tool

  1. Start with the example in the editor and identify the elements that answer your question.
  2. Replace the sample labels and values, previewing after each structural change.
  3. Review the diagram at its intended reading size, then keep the source and export the format your document accepts.

Syntax and interpretation

ConceptHow to apply it
CommitsEach commit is a modeled operation. IDs make it easier to discuss particular points in the history.
Branch operationsCreate a branch before checking it out. Merge into the intended current branch.
Renderer boundarygitGraph 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.