Skip to content

Git ​

A branch history, drawn the way people sketch it on a whiteboard: one lane per branch, tags above the commits, merges as filled dots.

yuhwa diagramyuhwa diagramEdit
yuhwa
git flow "Release flow" {
  commit "init" [tag: v0.1.0]
  branch feature/login
  commit "login form"
  commit "oauth"
  checkout main
  commit "fix typo"
  branch fix/cache [amber]
  commit "cache headers"
  checkout main
  merge fix/cache [tag: v0.1.1]
  merge feature/login [tag: v0.2.0]
}
linemeaning
commit ["message"] [props]a commit on the current branch
branch name [from X] [props]create a branch and switch to it; X is a branch, a commit id or a tag (default: the current commit)
checkout -b name / switch -c namethe same as branch name
checkout name / switch nameswitch to an existing branch
merge name ["message"] [props]a merge commit with two parents; the message defaults to Merge name
cherry-pick X ["message"] [props]copy commit X (id, tag or branch head) onto the current branch
tag v1tag the current commit

Commit and merge props:

propresult
tag: v1a tag pill above the commit
id: a1b2c3names the commit for from and cherry-pick; shown with direction: down
type: highlight / [highlight]a filled square, for the commit that matters
type: reverse / [reverse]a crossed circle, for a revert
a colour, like [red]colour of this commit

Branch props: a colour, label: "1.x" (shown instead of the name) and order: 2 (moves the lane; lanes otherwise follow creation order).

A cherry-picked commit is drawn as a dashed circle, with a dashed line back to the original. Picking a commit onto the branch it is already on gives a warning, as does a commit id used twice. History starts on main.

yuhwa diagramyuhwa diagramEdit
yuhwa
git hotfix "Hotfix on a release branch" {
  commit "v1.0" [tag: v1.0]
  commit "new api"
  checkout -b feature/search
  commit "search ui"
  checkout main
  commit "fix auth" [id: fix, highlight, tag: v1.1]
  merge feature/search [tag: v1.2]
  branch release/1.0 from v1.0 [label: "1.0.x", amber]
  cherry-pick fix [tag: v1.0.1]
}
header propresult
main: trunkname of the first branch
direction: downtop to bottom like git log --graph, with branch names at their heads (vertical is the old spelling)
direction: rightleft to right (default)
yuhwa diagramEdit
yuhwa
theme: midnight

git log "git log --graph" [direction: down, main: trunk] {
  commit "initial import" [id: 1a2b3c]
  branch api
  commit "add /orders" [id: 4d5e6f]
  checkout trunk
  commit "ci: cache deps" [id: 7a8b9c]
  checkout api
  commit "validate body" [id: 0d1e2f]
  checkout trunk
  merge api [id: 3a4b5c, tag: v2.0]
}

Adjusting the layout ​

When a line lands in the wrong place, move it. Select the panel in the visual editor and drag its handles, or write the offsets into the layout block by hand. Each line nudges one part of the history by a distance along the axis that part moves on, so a nudge keeps its meaning when you switch direction. Positive moves right on the time axis (down with direction: down) and away from main across it:

partwhat moves
featthe lane of branch feat, and every lane after it
v1.0, fix, c3one commit, and every commit after it, along the time axis; named by id, else its first tag, else its position (c1 is the first). A branch name wins: a commit with the same id or tag falls back to its position
c5^1the bend into commit c5 from its parent on another lane (where a branch starts), along the time axis
c5^2the bend into merge c5 from the merged branch
c5^pickthe dashed cherry-pick line to c5, in both directions: two numbers, DX DY
yuhwa diagramyuhwa diagramEdit
yuhwa
git flow "Release flow" {
  commit "init" [tag: v0.1.0]
  branch feature/login
  commit "login form"
  checkout main
  commit "fix typo"
  merge feature/login [tag: v0.2.0]
}

layout {
  flow at 0 0
  flow:feature/login 24
  flow:c3 36
  flow:v0.2.0^2 -24
}

flow at X Y pins the whole panel, like a node. A panel takes no size: its content decides that. Older files may write flow:c3 offset 36; the word offset is optional. Delete the lines to go back to the automatic drawing.

Examples ​

Git flow ​

A develop branch, a feature branch and a release branch merged both ways.

yuhwa diagramyuhwa diagramEdit
yuhwa
git gitflow "Git flow" {
  commit "1.0" [tag: v1.0]
  branch develop [blue]
  commit "start 1.1"
  branch feature/cart [green]
  commit "cart"
  commit "tests"
  checkout develop
  merge feature/cart
  branch release/1.1 [amber]
  commit "bump version"
  checkout main
  merge release/1.1 [tag: v1.1]
  checkout develop
  merge release/1.1
}

Trunk-based ​

Short branches, merged the same day.

yuhwa diagramEdit
yuhwa
theme: pastel

git trunk "Trunk-based" [main: trunk] {
  commit
  branch a [purple]
  commit "flag off"
  checkout trunk
  merge a
  branch b [teal]
  commit "small fix"
  checkout trunk
  merge b
  commit [tag: deploy-42]
}

git log ​

yuhwa diagramEdit
yuhwa
theme: terminal

git log "git log --graph --oneline" [direction: down] {
  commit "initial import" [id: 9fceb02]
  branch release/2.0
  commit "bump version" [id: 3a1e5d7]
  checkout main
  commit "add payments" [id: b7c41f0]
  commit "fix flaky test" [id: 0e8d2a9]
  checkout release/2.0
  commit "changelog" [id: 6d2f3b1, tag: v2.0.0]
  checkout main
  merge release/2.0 [id: c4a9e12]
}

Released under the MIT License.