Cookie Consent by Free Privacy Policy Generator ๐Ÿ“Œ Illustrating git Branching with Markdown and Mermaid.js

๐Ÿ  Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeitrรคge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden รœberblick รผber die wichtigsten Aspekte der IT-Sicherheit in einer sich stรคndig verรคndernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch รผbersetzen, erst Englisch auswรคhlen dann wieder Deutsch!

Google Android Playstore Download Button fรผr Team IT Security



๐Ÿ“š Illustrating git Branching with Markdown and Mermaid.js


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

Occasionally I find myself needing to write about git commands or workflows, either as I am educating new developers or as I am documenting a team's git strategies.

While graphical git tooling such as GitKraken can help with this if you have a practical example, sometimes its nice to have a nice and clean diagram of example commits.

In this article we'll explore how Mermaid.js can help you generate clean and minimalist git graphs using only markdown.

For those not familiar, Mermaid.js is an open-source JavaScript library that converts specialized markdown into diagrams on your page. It is fantastic and can do many diagrams including entity relationship diagrams, class diagrams, sequence diagrams, and more.

Mermaid.js integrates into GitHub, Visual Studio Code, Polyglot Notebooks, and others. Let's see how it handles git commits.

Displaying Basic Commits

At the most basic level, a git graph starts with a gitGraph element and then a series of commit statements.

gitGraph
    commit
    commit
    commit

Git Graph

This creates a git timeline from left to right where the leftmost commit is the first one and the rightmost is the last one.

Notice that the names of each commit are randomly assigned and start with the 1-based index of the commit in the timeline followed by a dash and then the beginnings of a globally unique identifier.

If you want to customize the display of an individual commit, you can provide an id: node followed by the text to use in quotes.

Additionally, you can customize the theme of the graph via the %%{init statement by providing a value of base, forest, dark, default, or neutral. I happen to like base so the remainder of the graphs will feature that theme.

%%{init: { 'theme': 'base' } }%%
gitGraph
    commit
    commit id: "Fixed Issue #42"
    commit

Git Graph

git Branching in Mermaid.js

Of course, a git graph without any sort of branching or merging is both boring and not generally helpful. Let's take a look at a simple graph involving two branches:

%%{init: { 'theme': 'base' } }%%
gitGraph
    commit
    commit
    branch feature
    commit

Git Graph

Here all commits start on the main branch and then diverge onto the feature branch after the branch feature statement.

If you want to switch back to another branch without creating a new branch, you can do so with checkout branchname.

Finally, if you want to illustrate merging a branch into another, first checkout the target branch and then use merge branchname to indicate that the second branch was merged into your current branch.

%%{init: { 'theme': 'base' } }%%
gitGraph
    commit
    commit
    branch feature
    commit id: "Dark Theme"
    checkout main
    merge feature
    commit

Git Graph

Using branch, checkout, and merge strategically, you can quickly create complex git situations to help illustrate real-world usage scenarios.

%%{init: { 'theme': 'base' } }%%
gitGraph
    commit
    branch feature
    checkout main
    commit
    branch bugfix
    commit
    checkout feature
    commit id: "Dark Theme"
    checkout main
    merge feature
    commit
    checkout bugfix
    commit id: "Fixed Null Ref"
    checkout main
    merge bugfix
    commit

Git Graph

Annotating git Commits in Mermaid.js

While commit, branch, checkout, and merge are all you need for basic diagrams, sometimes you can benefit from highlighting certain commits with tag names or symbols.

First, any commit can be annotated with a tag by specifying tag: and then the name of the tag in quotes. This can be combined with id: if desired.

%%{init: { 'theme': 'base' } }%%
gitGraph
    commit tag: "v0.4.0"
    branch feature
    checkout main
    commit
    branch bugfix
    commit
    checkout feature
    commit id: "Dark Theme"
    checkout main
    merge feature
    commit tag: "v0.4.1"
    commit
    checkout bugfix
    commit id: "Fixed Null Ref"
    checkout main
    merge bugfix tag: "v0.4.2"
    commit

Git Graph

Secondly, each commit has a type: associated with it. By default this is the NORMAL type, but you can also specify type: REVERSE to indicate a commit with an X through it or type: HIGHLIGHT to use a square instead of a circle. Note that the type: attributes do not use quotes while the id: and tag: attributes do.

%%{init: { 'theme': 'base' } }%%
gitGraph
    commit tag: "v0.4.0"
    branch feature
    checkout main
    commit
    branch bugfix
    commit id: "Whoopsies" type: REVERSE
    checkout feature
    commit id: "Dark Theme"
    checkout main
    merge feature
    commit tag: "v0.4.1"
    commit type: HIGHLIGHT
    checkout bugfix
    commit id: "Fixed Null Ref"
    checkout main
    merge bugfix tag: "v0.4.2"

Git Graph

Closing Thoughts

I'm personally a huge fan of using Mermaid.js to generate git graphs. The syntax resembles the appropriate git commands for working with branching and the resulting graphs are attractive, simple, and help convey git concepts to new team members.

I personally plan on using Mermaid.js graphs going forward for any git related articles or documentation.

Stay tuned for more articles on Mermaid.js and the awesome things you can build with it!

...



๐Ÿ“Œ Illustrating git Branching with Markdown and Mermaid.js


๐Ÿ“ˆ 111.04 Punkte

๐Ÿ“Œ Git 101 for Beginners: Learn Git Commands, Branching, and Collaboration


๐Ÿ“ˆ 45.68 Punkte

๐Ÿ“Œ Sequence Diagrams in Markdown with Mermaid.js


๐Ÿ“ˆ 39.29 Punkte

๐Ÿ“Œ Mind Maps in Markdown with Mermaid.js


๐Ÿ“ˆ 39.29 Punkte

๐Ÿ“Œ Git Branching and Merging


๐Ÿ“ˆ 36.33 Punkte

๐Ÿ“Œ Git Branching and Merging: Navigating the Code Cosmos


๐Ÿ“ˆ 36.33 Punkte

๐Ÿ“Œ FeiFlow - An Opinioned Git Branching And Release Management Strategy


๐Ÿ“ˆ 36.33 Punkte

๐Ÿ“Œ Mastering Git: Branching and Merging โ€“ Part 2


๐Ÿ“ˆ 36.33 Punkte

๐Ÿ“Œ Illustrating Istioโ›ต


๐Ÿ“ˆ 35.42 Punkte

๐Ÿ“Œ Branching & Merging in Git: Level up your Version Control | Learn with Dr. G


๐Ÿ“ˆ 34.56 Punkte

๐Ÿ“Œ Git Merge vs. Rebase: Understanding Branching Strategies for a Cleaner Workflow


๐Ÿ“ˆ 34.56 Punkte

๐Ÿ“Œ Git branching strategy


๐Ÿ“ˆ 34.56 Punkte

๐Ÿ“Œ Mastering Git Branching Strategies: Best Practices for Organizing Your Development Workflow


๐Ÿ“ˆ 34.56 Punkte

๐Ÿ“Œ git switch and git checkout โ€“ How to switch branches in git


๐Ÿ“ˆ 29.8 Punkte

๐Ÿ“Œ markdown-slides: modern slides with markdown


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ CVE-2019-25103 | simple-markdown 0.5.1 simple-markdown.js redos


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ CVE-2019-19619 | Documize up to 3.5.0 Markdown markdown.go cross site scripting


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Discount 2.2.3a markdown.c islist Markdown memory corruption


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Discount 2.2.3a markdown.c isfootnote Markdown memory corruption


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Discount 2.2.3a markdown.c quoteblock Markdown memory corruption


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ OSCP-Exam-Report-Template-Markdown - Markdown Templates For Offensive Security OSCP, OSWE, OSCE, OSEE, OSWP Exam Report


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ transformers up to 0.32.x Markdown Qiita::Markdown cross site scripting


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ CVE-2019-25102 | simple-markdown 0.6.0 simple-markdown.js redos (ID 73)


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Discount 2.2.3a markdown.c isfootnote Markdown Pufferรผberlauf


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Discount 2.2.3a markdown.c islist Markdown Pufferรผberlauf


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Discount 2.2.3a markdown.c quoteblock Markdown Pufferรผberlauf


๐Ÿ“ˆ 28.64 Punkte

๐Ÿ“Œ Intel goes after TSMC's foundry market share by branching into Arm chips and focusing on U.S. manufacturing


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Source Code Management and Branching Strategies for CI/CD


๐Ÿ“ˆ 26.99 Punkte

๐Ÿ“Œ Immortality developer Sam Barlow and Half Mermaid Productions announce two new games


๐Ÿ“ˆ 26.74 Punkte

๐Ÿ“Œ Getting Started With Neon Branching


๐Ÿ“ˆ 25.22 Punkte

๐Ÿ“Œ Microsoft is branching out from custom Xbox controllers to custom chocolate controllers


๐Ÿ“ˆ 25.22 Punkte

๐Ÿ“Œ Solve the GPT Branching Problem with an Artifact Pipeline


๐Ÿ“ˆ 25.22 Punkte

๐Ÿ“Œ Amazon's Ring May Be Branching Out Beyond Outdoor Cameras


๐Ÿ“ˆ 25.22 Punkte

๐Ÿ“Œ GitLive adds support for more branching strategies including GitFlow


๐Ÿ“ˆ 25.22 Punkte

๐Ÿ“Œ GitLab Community Edition/Enterprise Edition up to 13.0.1 Mermaid Payload PUT Request privileges management


๐Ÿ“ˆ 24.97 Punkte











matomo