Overview
Git graph diagrams in Sirena visualize Git repository history, showing commits, branches, merges, and cherry-pick operations. These diagrams provide a clear visual representation of version control workflows, making them ideal for documentation, tutorials, and code review discussions.
Git graphs are useful for:
-
Documenting branching strategies and workflows
-
Visualizing feature development and integration
-
Creating tutorials on Git operations
-
Illustrating merge and rebase scenarios
-
Showing release management processes
-
Explaining cherry-pick operations in pull requests
Syntax specification
Diagram declaration
Git graphs are declared using the gitGraph keyword with optional orientation:
gitGraph
<diagram-content>
Commits
Commits are the basic building blocks of a git graph:
commit
Commit with options
Commits can have custom identifiers, types, and tags:
commit id: "abc123"
commit type: HIGHLIGHT
commit tag: "v1.0.0"
commit id: "Initial" type: NORMAL tag: "release"
Where:
id-
Custom identifier for the commit (quoted or unquoted string)
type-
Visual style of the commit (NORMAL, REVERSE, HIGHLIGHT)
tag-
Version tag or label displayed above the commit
Examples
Simple linear history
gitGraph
commit id: "Initial commit"
commit id: "Add feature"
commit id: "Fix bug"
commit id: "Release" tag: "v1.0"
This creates a simple linear history with four commits, where the last commit is tagged as version 1.0.
Feature branch workflow
gitGraph
commit id: "Initial"
branch develop
checkout develop
commit id: "Setup"
branch feature
checkout feature
commit id: "Implement feature"
commit id: "Add tests"
checkout develop
merge feature
checkout main
merge develop tag: "v1.0"
This demonstrates:
-
Creating a develop branch from main
-
Creating a feature branch from develop
-
Working on the feature with multiple commits
-
Merging the feature back to develop
-
Merging develop to main with a release tag
Multiple parallel branches
gitGraph
commit id: "Start"
branch feature-a
branch feature-b
checkout feature-a
commit id: "Feature A - Step 1"
commit id: "Feature A - Step 2"
checkout feature-b
commit id: "Feature B - Step 1"
checkout main
commit id: "Hotfix"
checkout feature-a
merge main id: "Sync hotfix"
commit id: "Feature A - Complete"
checkout main
merge feature-a
checkout feature-b
commit id: "Feature B - Complete"
checkout main
merge feature-b
This shows:
-
Multiple feature branches created simultaneously
-
Independent development on each branch
-
Hotfix applied to main and synchronized to feature-a
-
Sequential merging of completed features
Using commit types for emphasis
gitGraph
commit id: "Init"
commit id: "Regular work" type: NORMAL
branch feature
checkout feature
commit id: "Important change" type: HIGHLIGHT
commit id: "Experimental" type: REVERSE
commit id: "Feature done" type: HIGHLIGHT
checkout main
merge feature tag: "v2.0"
This demonstrates:
-
NORMAL- Standard commits (default) -
HIGHLIGHT- Important or milestone commits -
REVERSE- Experimental or tentative commits -
Using types to visually distinguish commit importance
Cherry-pick operation
gitGraph
commit id: "Base"
branch develop
checkout develop
commit id: "Feature 1"
commit id: "Feature 2"
commit id: "Critical fix"
checkout main
cherry-pick id: "Critical fix" tag: "backport"
checkout develop
commit id: "Feature 3"
This shows:
-
Development happening on develop branch
-
A critical fix committed to develop
-
Cherry-picking the fix back to main
-
Tagging the cherry-picked commit as a backport
-
Continued development on develop branch
Complex workflow with tags and types
gitGraph
commit id: "v0.1.0" tag: "v0.1.0"
branch develop
checkout develop
commit id: "Setup CI"
branch feature-auth
checkout feature-auth
commit id: "Add login" type: HIGHLIGHT
commit id: "Add logout"
checkout develop
branch feature-api
checkout feature-api
commit id: "API endpoint"
checkout develop
merge feature-auth
commit id: "Integration tests"
checkout main
commit id: "Security patch" type: HIGHLIGHT
checkout develop
merge main id: "Sync security"
merge feature-api
commit id: "Prepare release" type: HIGHLIGHT
checkout main
merge develop tag: "v1.0.0"
This comprehensive example includes:
-
Initial release tag on main
-
Develop branch for integration
-
Multiple feature branches in parallel
-
Security patch on main
-
Synchronizing security patch to develop
-
Merging features to develop
-
Final release merge with version tag
-
Using HIGHLIGHT type for important commits
Horizontal layout
gitGraph LR:
commit id: "Start"
branch feature
checkout feature
commit id: "Work"
commit id: "More work"
checkout main
merge feature tag: "done"
This demonstrates:
-
Horizontal layout using
LR:orientation -
Better for wide displays or documentation
-
Same functionality as vertical layout
Features
Automatic branch creation
Branches are created automatically when first referenced:
gitGraph
commit
branch feature
checkout feature
commit
The main branch exists by default as the starting point.
Branch naming
Branch names can contain letters, numbers, hyphens, and underscores:
gitGraph
branch feature-123
branch bug_fix_2
branch dev-v2
Commit identifiers
Commit IDs can be quoted or unquoted:
gitGraph
commit id: abc123
commit id: "commit with spaces"
commit id: 'single-quoted'
Limitations
Best practices
Use meaningful commit IDs
Choose descriptive identifiers for important commits:
%% Good
gitGraph
commit id: "Initial setup"
commit id: "Add authentication"
commit id: "Fix login bug"
%% Less clear
gitGraph
commit id: "a1b2c3"
commit id: "commit2"
commit id: "fix"
Tag releases and milestones
Use tags to mark important points in history:
gitGraph
commit id: "Development"
commit id: "Feature complete" tag: "RC1"
commit id: "Bug fixes"
commit id: "Production ready" tag: "v1.0.0"
Use commit types strategically
Apply types to emphasize important commits:
-
HIGHLIGHT- Major features, releases, critical fixes -
REVERSE- Experimental changes, work-in-progress -
NORMAL- Regular development work (default)
gitGraph
commit type: NORMAL
commit type: HIGHLIGHT id: "Major feature" tag: "beta"
commit type: REVERSE id: "Experimental API"
commit type: NORMAL
Keep branch names concise
Use short, descriptive branch names:
%% Good
gitGraph
branch feature-auth
branch hotfix-login
branch release-2.0
%% Too verbose
gitGraph
branch feature-implement-user-authentication-system
branch hotfix-fix-the-login-page-redirect-issue
Order branches logically
Use branch ordering for clarity:
gitGraph
branch main order: 0
branch release order: 1
branch develop order: 2
branch feature order: 3
branch hotfix order: 4
This creates a logical top-to-bottom hierarchy.