gitgraph.js
gitgraph.js copied to clipboard
Multiple branches at the same commit
It's often useful to have multiple branches pointing to the same commit. This doesn't seem to be supported with the @gitgraph/react
API.
For example, you might have a simple diagram like:
{(gitgraph) => {
const develop = gitgraph.branch("develop").commit();
const feature = gitgraph.branch("feature/1").commit();
develop.merge(feature);
}}
This works fine. However, if you want a diagram with multiple branches on the same commit, like this:

Then you seem to be out of luck. Adding a branch without following it up by its own divergent commit results in the branch not being rendered at all.
This means that, in addition to not being able to have multiple branches on the same commit, it's impossible to "leave a branch behind" while another branch keeps following the HEAD (except when merging, in which case you're limited to a maximum of one branch "left behind" per merge - #204).
I don't know what the internals look like but from an API user's perspective the most straightforward way to fix this seems to be to allow something like the following in order to produce the above diagram:
{(gitgraph) => {
const develop = gitgraph.branch("develop").commit();
const feature = gitgraph.branch("feature/1").commit();
develop.merge(feature);
feature.branch("release/1");
}}
Note that this is distinct from #143 because this covers branches, not tags.
That's a very good point @briangordon, thanks for raising this.
I marked this as a feature to be develop. We should be able to create multiple branches for the same commit 👍
Here is another example showing this behaviour with some git shell commands to reproduce it.
For example,
const master = gitgraph.branch("master").commit("A");
const feature = master.branch("feature");
I would expect: a single commit "A" with two branches "master" and "feature".
Actual: a single commit "A" with one branch "master" ( The feature branch only shows when a commit() is made on it )
In shell:
mkdir project
cd project
git init
echo 'A' >> README.md
git add README.md
git commit -m "A"
git checkout -b feature
Gives (Git Graph in VSCode)
Changes in master should leave feature alone:
git checkout master
echo 'B' >> README.md
git add README.md
git commit -m "B"
I don't think it is possible to do this in gitgraph.js
Ask when this function can be done? I need that on my side, too
There's an open draft PR that's still valid and that adds the stories proving this feature doesn't work yet: https://github.com/nicoespeon/gitgraph.js/pull/273
But no-one tackled this feature yet—I personally won't have time to do it so I'm calling for contributors help 🙏