diff --git a/packages/mermaid/src/diagrams/git/gitGraphAst.ts b/packages/mermaid/src/diagrams/git/gitGraphAst.ts index b04e78d8c..9a26d32f7 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphAst.ts +++ b/packages/mermaid/src/diagrams/git/gitGraphAst.ts @@ -399,14 +399,11 @@ export const checkout = function (branch: string) { } else { curBranch = branch; const id = branches.get(curBranch); - - if (id === null || id === undefined) { - throw new Error('Branch ' + branch + ' has no commits'); + if (id === undefined || !id) { + head = null; + } else { + head = commits.get(id) ?? null; } - if (commits.get(id) === undefined) { - throw new Error('Branch ' + branch + ' has no commits'); - } - head = commits.get(id) ?? null; } };