Git graphs: branches, merges, cherry-pick

Git graphs: branches, merges, cherry-pick

puml.online

简介 / Introduction

Git graph diagrams help developers understand branch creation, merge conflicts, and cherry-pick operations. Both PlantUML and Mermaid support text-based Git branch diagrams, making them easy to embed in documentation, READMEs, or blog posts. This article uses the same scenario — branching feature from main, making commits, merging back, and creating a hotfix — rendered in both engines for direct comparison.

PlantUML 版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@startuml
skinparam defaultFontSize 14
gitgraph
commit id: "Initial commit"
branch feature
checkout feature
commit id: "Add feature A"
commit id: "Add feature B"
checkout main
merge feature id: "Merge feature"
branch hotfix
checkout hotfix
commit id: "Fix critical bug"
checkout main
merge hotfix id: "Merge hotfix"
@enduml

Mermaid 版

1
2
3
4
5
6
7
8
9
10
11
gitGraph
commit id: "Initial commit"
branch feature
commit id: "Add feature A"
commit id: "Add feature B"
checkout main
merge feature id: "Merge feature"
branch hotfix
commit id: "Fix critical bug"
checkout main
merge hotfix id: "Merge hotfix"

对比 / Side-by-side

Feature PlantUML Mermaid
Declare branch branch <name> branch <name>
Switch branch checkout <name> checkout <name>
Commit commit id: "msg" commit id: "msg"
Merge merge <branch> id: "msg" merge <branch> id: "msg"
Cherry-pick cherrypick id: "xxx" Not supported
Delete branch delete branch <name> Not supported
Tag tag: "v1.0" tag: v1.0

小结 / Wrap-up

PlantUML’s gitgraph syntax is more complete, supporting cherrypick, delete branch, and other advanced operations, making it suitable for complex team workflow documentation. Mermaid’s gitGraph is more lightweight and easier to embed in Markdown blogs, though advanced features like cherry-pick and branch deletion are not yet supported. Both allow style customization via skinparam / gitGraph directives — choose based on your project’s complexity and rendering environment.

Appendix: Cherry-pick Example (PlantUML only)

1
2
3
4
5
6
7
8
9
10
@startuml
gitgraph
commit id: "Initial commit"
branch feature
checkout feature
commit id: "Experimental feature"
checkout main
cherrypick id: "Experimental feature"
tag: "v1.1"
@enduml

Mermaid’s current version does not support cherry-pick visualization; commits in that form are silently ignored.

  • Title: Git graphs: branches, merges, cherry-pick
  • Author: puml.online
  • Created at : 2026-09-20 09:00:00
  • Updated at : 2026-09-29 01:06:38
  • Link: https://puml.online/blog/git-graph-branch-merge-en/
  • License: This work is licensed under CC BY-NC-SA 4.0.