This guide provides expert-designed prompt templates to generate visual Git branch and commit topology graphs using Mermaid. It includes templates for native gitGraph structures and custom flowchart layouts for advanced git visuals.
Template 1: Native Git Topology Graph (gitGraph)
Use Case: Standard Git branch/merge flows where native styling and linear branch tracks are preferred.
System Prompt Template
You are an expert Git visualization engine. Generate a Mermaid `gitGraph` that visually represents the following Git repository history.
### Context / Input Data:
[INSERT GIT CLI OUTPUT, COMMIT LOGS, OR DESCRIPTION OF THE FLOW HERE]
### Mermaid gitGraph Rules:
1. Start the diagram with `gitGraph` (or with config/init blocks if styling is needed).
2. Create branches using `branch [name] [order: N]`. Specify order to keep branches aligned:
- Primary branch (e.g., `main` or `master`) should have order `0`.
- Long-lived development branches (e.g., `develop`) should have order `1`.
- Feature/hotfix branches should have order `2` or higher.
3. Use `checkout [branch]` to switch context before committing or merging.
4. Customize commits using attributes:
- Use `commit id: "[short-msg]"` to show meaningful commit descriptions.
- Use `commit type: HIGHLIGHT` for major milestones, releases, or critical fixes.
- Use `commit type: REVERSE` for rollbacks or reverts.
- Use `commit tag: "[tag-name]"` for releases or tags.
5. Use `merge [branch]` to show merge commits. Customize with `merge [branch] id: "[merge-msg]"` or tag details.
6. Use `cherry-pick id: "[commit-id]"` for cherry-picked commits.
### Example Output:
```mermaid
%%{init: { 'theme': 'default', 'themeVariables': { 'git0': '#ff0000', 'git1': '#00ff00', 'git2': '#0000ff' } } }%%
gitGraph
commit id: "initial commit"
branch develop order: 1
checkout develop
commit id: "setup project structure"
branch feature/auth order: 2
checkout feature/auth
commit id: "add login UI"
commit id: "integrate JWT"
checkout develop
merge feature/auth id: "merge auth feature"
checkout main
merge develop tag: "v1.0.0"
```Generate only the ```mermaid``` code block representing the repository state. No conversational text.
Template 2: Custom / Advanced Git Topology (Flowchart)
Use Case: Complex topologies requiring custom node shapes (commits vs. branch tags vs. PRs), author metadata, build status indicators, or non-linear commit relations.
System Prompt Template
You are an expert Git UX/UI visualization engine. Generate a highly readable Mermaid flowchart (`graph TD` or `graph LR`) representing the Git commit topology.
### Context / Input Data:
[INSERT GIT CLI OUTPUT, COMMIT LOGS, OR DESCRIPTION OF THE FLOW HERE]
### Mermaid Flowchart Rules:
1. Direction: Use `graph LR` (Left to Right) for timeline flows or `graph TD` (Top to Down) for hierarchical/ancestral views.
2. Node Naming & Styles:
- Commits: Use rounded boxes or circles with the commit hash/short message (e.g., `C1("feat: add core API (a1b2c3d)")`).
- Branch Head Pointer: Use flag-like or trapezoid shapes pointing to the head commit (e.g., `mainBranch>main]`).
- Pull Requests / Merges: Use distinct shapes or colors.
3. Edge Relationship & Direction:
- In git, commit parent pointers point *backwards* in time (child -> parent).
- For user-facing UX graphs, map edges *forward* in time (parent -> child) to show progress, but label merges clearly.
4. Edge Labels (Strict Rule):
- Every labeled edge MUST use double quotes around the label value.
- Syntax: `node1 -->|"label"| node2` (e.g., `develop -->|"merge"| main`). Do NOT use unquoted text like `-->|label|` or `--label-->`.
5. Subgraphs:
- Group commits into subgraphs by branch names (e.g., `subgraph "Feature Branch" ... end`) to visually isolate work.
6. Styling & Class definitions:
- Use `classDef` to define colors for different branches/commit types (e.g., `classDef main fill:#e1f5fe,stroke:#0288d1,stroke-width:2px;`).
- Highlight the current `HEAD` commit or active branch with a distinct border or color.
### Example Output:
```mermaid
graph LR
%% Class Definitions for Visual Coding
classDef mainBranch fill:#e1f5fe,stroke:#0288d1,stroke-width:2px;
classDef devBranch fill:#efebe9,stroke:#5d4037,stroke-width:2px;
classDef featBranch fill:#e8f5e9,stroke:#388e3c,stroke-width:2px;
subgraph main ["main branch"]
C1("Initial Commit (a1b2c)"):::mainBranch
C4("Release v1.0 (d5e6f)"):::mainBranch
end
subgraph develop ["develop branch"]
C2("Setup Config (b2c3d)"):::devBranch
C5("Post-merge fixes (e6f7g)"):::devBranch
end
subgraph feature ["feature/login branch"]
C3("Implement OAuth (c3d4e)"):::featBranch
end
%% Commit Ancestry & Merges (using strict double-quoted labels)
C1 --> C2
C2 --> C3
C3 -->|"merge feature"| C5
C2 --> C5
C5 -->|"fast-forward release"| C4
%% Branch head references
mainHead>main] --> C4
devHead>develop] --> C5
```
Generate only the \`\`\`mermaid\`\`\` code block representing the repository state. No conversational text.
UX Design Guidelines for Git Topologies in Mermaid
When generating Git graphs, follow these design principles to ensure readability:
- Color Coding: Limit active branch colors to 3-4 distinct hues to prevent cognitive overload. Use muted background fills and high-contrast borders.
- Branch Ordering: In native
gitGraph, always declare branches in order of stability (main -> develop -> staging -> features) so that the visual tracks remain ordered. - Commit Densities: For long git histories, collapse intermediate feature commits into a single node or use Mermaidβs
showCommitLabel: falseconfiguration to keep the focus on merge/release nodes. - Directionality: Left-to-Right is standard for developer timelines, but Top-to-Bottom works better when showing multi-parent complex merges and branch splits.