Giter Site home page Giter Site logo

svengreb / styleguide-git Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 0.0 503 KB

An opinionated, yet universally applicable Git style guide

License: MIT License

JavaScript 88.02% Shell 11.98%
styleguide style guide git commit message standard conventions codestyle

styleguide-git's Introduction

An opinionated, yet universally applicable Git style guide.

To present Git commits and branches in an organized, standardized, and easy-to-read manner, this style guide describes how the content should be structured, spelled and formatted.

There are only some strict rules but mostly guidelines since we are more interested in content than formatting while the review process might help contributors to conform to this guide later on.

Introduction

Commit messages are important parts of communication between contributors and the lifecycle of a project: its past and its future. It is the only place that captures not only what was changed, but why.

For open source project communities it‘s important to maintain good habits of communication in all forms. A well-crafted commit message can save a lot of time, overhead and helps to speed up development processes.

Structural Split Of Changes

If a code change can be split into a sequence of patches/commits, then it should be split. Less is not more.

The cardinal rule for creating good commits is to ensure there is only one logical change per commit. There are many reasons why this is an important rule:

  • The smaller the amount of code being changed, the quicker and easier it is to review and identify potential flaws.
  • Revert broken commits is much easier if there are not other unrelated code changes entangled with the original commit if a change is found to be flawed later.
  • Small well defined changes will aid in isolating exactly where the code problem was introduced when troubleshooting problems using Git‘s bisect capability.
  • Small well defined changes aid in isolating exactly where- and why a piece of code came from when browsing history using Git annotate or blame.

Bad Practices

  • Mixing whitespace changes with functional code changes. The whitespace changes will obscure the important functional changes, making it harder for a reviewer to correctly determine whether the change is correct.
    • The change should be split into two commits, one with the whitespace changes, one with the functional changes.
  • Mixing two unrelated functional changes. Without a structural split of changes it will be harder to identify flaws if two unrelated changes are mixed together. If it becomes necessary to later revert a broken commit, the two unrelated changes will need to be untangled, with further risk of bug creation.
  • Sending large new features in a single giant commit. The code for a new feature is only useful when all of it is present, but this does not imply that the entire feature should be provided in a single commit.
    • New features may entail refactoring existing code so it is highly desirable that any refactoring is done in commits which are separate from those implementing the new feature. This helps reviewers and test suites validate that the refactoring has no unintentional functional changes.
    • Newly written code can often be split up into multiple pieces that can be independently reviewed. For example, changes which add new internal APIs/classes, can be in self-contained commits leading to easier code review and allows other developers to cherry-pick small parts of the work, if the entire new feature is not immediately ready for merge.
    • Code that affects public APIs should be done in commits separate from the actual internal implementation. This will encourage the author and reviewers to think about the generic API design, and not simply pick a design that is easier for their currently chosen internal implementation.

Commit Messages

The commit message must contain all the information required to fully understand & review the patch. Less is not more.

As important as the content of the change is the content of the commit message describing it. The purpose of a commit message is to summarize a change, but the purpose of summarizing a change is to help to understand the code. The information to be put into a message should be valuable and useful for reviewers and the projects community.

Having a story in the Git history will make a huge difference in how others perceive the project. Taking great care in commit messages will help to increase the long-term overall quality.

  • The first line is important. The message summary of the commit has special significance. It is used in many places like the Git history headline, git annotate- and merge messages or email subject lines where space is at a premium. As well as summarizing the change itself, it should take care to detail what part of the code is affected.
  • Describe the intent and motivation behind the changes. Describe why the code has been written this way and document the overall code structure in the message body, particularly for large changes.
  • Include the GitHub issue ID and additional references in the message footer. This will automatically fire some hooks to track the commit in related GitHub repository issues- and pull requests and is required to contribute to a project.
  • Reviewers can understand what the original problem was. The commit message should have a clear statement as to what the original problem is. The GitHub issue ID is merely interesting historical background on how the problem was identified and has been discussed within the community, but it should be possbile to review a proposed patch for correctness without having to read the whole ticket.

Elements and their structure

A Git commit message follows this format:

<summary>

<body>

<footer>

Message Summary

The first line is the one-sentence concise subject about the changes introduced by the commit. The optimal total size of characters is 50 or less, but is limited to 72 characters and does not ended with a period. It uses the imperative mood and is separated from the message body by a single blank line.

Technical details that cannot be expressed in these strict size constraints should be put in the message body instead.

Message Body

The detailed description about the changes of the commit should be split into multiple logically separate paragraphs if necessary. It uses the imperative mood and the lines are wrapped at 72 characters.

Message Footer

This metadata block must contain the GitHub issue ID and is separated from the message body by a single blank line.

Multiple issues are separated by a comma and additional references can be added in the next lines.

Branch Naming

A branch should reflect the story of the commits it contains using a valuable and useful name to clarify its purpose during the development lifecycle and the persistency in the history.

This style guide follows the GitHub Flow branching model with the deviations and additional conventions described below.

Branches are an important major component for building open source projects regardless of the size. A well maintained branch merge story in the history will help to increase the long-term overall quality.

Core Branches

The infinite lifecycle core branch must be lowercase named master.

Story Branches

The lowercase name of a limited development lifecycle story branch must reflect the type separated by a slash from the issue ID and followed by the short and descriptive title using hyphen delimiters.

<TYPE>/<ISSUE_ID>-<TITLE>

Example: feature/gh-17-tokenizer-api

Story Type Prefixes

  • bugfix
  • feature
  • improvement
  • release
  • subtask
  • task
  • test

Every branch must contain issue ID which is important to automatically fire some hooks to track the commit in the related GitHub repository issues and pull requests and is required to contribute to a project.

A release branch is used to prepare a new tagged release version.

Tags

This style guide follows the GitHub Flow branching model with the deviations and additional conventions described below using the “Semantic Versioning 2“ specification.

All version tags are created in the master core branch to specify which commits reflects a release version as defined by the release branch name prefix.

  • Only use annotated tags. Allows to include the name of the project followed by the version number to the commit message.
  • Always add the v prefix character to version tags. Clarifies the tag type as specified by SemVer.
  • Every version tag must be signed. Ensures that the version has been tested and approved by the project owner or an authorized project contributor.

Copyright © 2016-present Sven Greb

styleguide-git's People

Contributors

svengreb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

styleguide-git's Issues

Migrate to MIT license

Currently the project code is licensed under the Apache 2.0 license. This often causes problems when developers want to use the project or code parts of it in another project (mainly code editors and UI frameworks) licensed under a less restricted license.

Therefore the project will migrate to the MIT license which is more open, unrestricted and the most used license for open source projects (Facebook recently also re-licensed React).

From `master` to `main`

Many communities, like on GitHub and GitLab as well as the wider Git community, renamed the default branch from master to main.
Historically, the default name for this initial branch was master. This term came from Bitkeeper, a predecessor to Git. Bitkeeper referred to the source of truth as the "master repository" and other copies as "slave repositories". This shows how common master/slave references have been in technology, and the difficulty in knowing how the term master should be interpreted.
During the creation of the “Black Lives Matter“ initiative the demand to get rid of the master/slave naming got louder and louder and therefore large projects and platforms like GitHub/GitLab started made the first step and pushed towards this goal.
These organizations are not alone in the Git ecosystem: the Git project announced to adapt these changes and the latest Git versions using main as default branch name when initializing a new repository.

As of October 1, 2020 the the default branch for newly-created repositories is now main and GitLab will apply this change with on June 6. 2021.
To make the transition as easy and fast as possible, GitHub create the github/renaming repository that assists projects to gradually rename the default branch from master to main. The process should be as seamless as possible for project maintainers and all of their contributors so the repository is the up-to-date guidance on how and when to rename the default branch. In January 19, 2021 GitHub also introduced a new feature for the web platform that supports maintainers to rename any branch that automates some tasks and ensures that internal GitHub information is updated as well. GitHub also ensures that links to deleted branches are now also redirected to the default branch of a repository.

Migration Tasks

All Arctic Ice Studio and Sven Greb projects adhere to this guide so each repository will gradually adapt to this change one after the other. Large projects like Nord with all of it's port projects will require a lot more time and effort to migrate regarding the goal and tooling compatibility of the actual project.
Smaller projects like my igloo dotfile repository, snowsaw as well as this style guide repository itself are way easier and can be done within the next few weeks.

To ensure the migration is documented and the status of each repository can be tracked, this issue will be kept open and used as umbrella ticket.

Private repositories are tracked internally as well on external (private) systems while the following affected public repositories and the corresponding issue are listed below.

  • arcticicestudio/arctic-landscape#
  • arcticicestudio/arctic-ocean-fractal#
  • arcticicestudio/icecore-hashids#
  • arcticicestudio/igloo#
  • nordtheme/alacritty#23
  • arcticicestudio/nord-atom-syntax#
  • arcticicestudio/nord-atom-ui#
  • arcticicestudio/nord-brackets#
  • arcticicestudio/nord-coda#
  • arcticicestudio/nord-conemu#
  • arcticicestudio/nord-dircolors#
  • nordtheme/web#236
  • arcticicestudio/nord-eclipse-syntax#
  • arcticicestudio/nord-emacs#
  • arcticicestudio/nord-gedit#
  • arcticicestudio/nord-gnome-terminal#
  • arcticicestudio/nord-guake#
  • arcticicestudio/nord-highlightjs#
  • arcticicestudio/nord-hyper#
  • arcticicestudio/nord-iterm2#
  • arcticicestudio/nord-java#
  • nordtheme/jetbrains#182
  • arcticicestudio/nord-konsole#
  • arcticicestudio/nord-mintty#
  • arcticicestudio/nord-notepadplusplus#
  • arcticicestudio/nord-putty#
  • nordtheme/slack#15
  • arcticicestudio/nord-sublime-text#
  • arcticicestudio/nord-terminal-app#
  • arcticicestudio/nord-terminator#
  • arcticicestudio/nord-termite#
  • arcticicestudio/nord-tilix#
  • arcticicestudio/nord-tmux#
  • nordtheme/vim#313
  • arcticicestudio/nord-visual-studio-code#
  • arcticicestudio/nord-xcode#
  • arcticicestudio/nord-xfce-terminal#
  • arcticicestudio/nord-xresources#
  • arcticicestudio/nord#
  • arcticicestudio/remark-preset-lint-arcticicestudio#
  • arcticicestudio/snowsaw#
  • arcticicestudio/styled-modern-normalize#
  • arcticicestudio/styleguide-java#
  • svengreb/styleguide-javascript#45
  • svengreb/styleguide-markdown#22
  • svengreb/website

GitHub Flow migration

Historical Background

Back on July 22 2017, this style guide for Git was created that also includes the compliance with Git Flow. Generally this branching model is really dynamic and can help a larger team to keep the overview of different story implementations while being able to build and deploy version backports. Using develop as the main branch also helps to make sure the master branch always contains stable versions.

Anyway, the model also comes with disadvantages like the overhead of keeping both develop and master in sync when tagging a new release version. The main target groups for this model are larger teams that work on projects with legacy support.

I've adapted to Git Flow because I liked the idea of having one branch that reflects the actual development state, but after using it for over 6 years I don't see any advantages in it anymore compared to other great models like GitHub Flow. I've checked the original Git Flow blog post of Vincent Driessen again and was amazed that he recently (March 5, 2020) added an update at the top of the post that exactly matches my opinion regarding the fact that Git Flow is not suitable these days, comes with too much overhead and that he now recommends to use GitHub Flow instead:

Note of reflection (March 5, 2020)

This model was conceived in 2010, now more than 10 years ago, and not very long after Git itself came into being. In those 10 years, git-flow (the branching model laid out in this article) has become hugely popular in many a software team to the point where people have started treating it like a standard of sorts — but unfortunately also as a dogma or panacea.

During those 10 years, Git itself has taken the world by a storm, and the most popular type of software that is being developed with Git is shifting more towards web apps — at least in my filter bubble. Web apps are typically continuously delivered, not rolled back, and you don't have to support multiple versions of the software running in the wild.

This is not the class of software that I had in mind when I wrote the blog post 10 years ago. If your team is doing continuous delivery of software, I would suggest to adopt a much simpler workflow (like GitHub flow) instead of trying to shoehorn git-flow into your team.

If, however, you are building software that is explicitly versioned, or if you need to support multiple versions of your software in the wild, then git-flow may still be as good of a fit to your team as it has been to people in the last 10 years. In that case, please read on.

To conclude, always remember that panaceas don't exist. Consider your own context. Don't be hating. Decide for yourself.

This update perfectly reflects the way I thought about the Git Flow model quite a while now.
Therefore I've finally decided to switch to GitHub Flow and retire the good old develop in favor of master as the one and only single-source-of-truth™️.

Migration Tasks

Since all Arctic Ice Studio projects adhere to this guide each repository must gradually adapt to this change one after the other. Large projects like Nord with all of it's port projects will require a lot more time and effort to migrate regarding the goal and tooling compatibility of the actual project.
Smaller projects like my igloo dotfile repository, snowsaw as well as this style guide repository itself are way easier and can be done within the next few weeks.

To ensure the migration is documented and the status of each repository can be tracked, this issue will be kept open and used as umbrella ticket.

Private repositories are tracked internally as well on external (private) systems while the following affected public repositories and the corresponding issue are listed below.

  • arcticicestudio/arctic-landscape#
  • arcticicestudio/arctic-ocean-fractal#
  • arcticicestudio/icecore-hashids#
  • arcticicestudio/igloo#240
  • nordtheme/alacritty#21
  • arcticicestudio/nord-atom-syntax#
  • arcticicestudio/nord-atom-ui#
  • arcticicestudio/nord-brackets#
  • arcticicestudio/nord-coda#
  • arcticicestudio/nord-conemu#
  • arcticicestudio/nord-dircolors#
  • nordtheme/web#229
  • arcticicestudio/nord-eclipse-syntax#
  • arcticicestudio/nord-emacs#
  • arcticicestudio/nord-gedit#
  • arcticicestudio/nord-gnome-terminal#
  • arcticicestudio/nord-guake#
  • arcticicestudio/nord-highlightjs#
  • arcticicestudio/nord-hyper#
  • arcticicestudio/nord-iterm2#
  • arcticicestudio/nord-java#
  • nordtheme/jetbrains#180
  • arcticicestudio/nord-konsole#
  • arcticicestudio/nord-mintty#
  • arcticicestudio/nord-notepadplusplus#
  • arcticicestudio/nord-putty#
  • nordtheme/slack#13
  • arcticicestudio/nord-sublime-text#
  • arcticicestudio/nord-terminal-app#
  • arcticicestudio/nord-terminator#
  • arcticicestudio/nord-termite#
  • arcticicestudio/nord-tilix#
  • arcticicestudio/nord-tmux#
  • nordtheme/vim#311
  • arcticicestudio/nord-visual-studio-code#
  • arcticicestudio/nord-xcode#
  • arcticicestudio/nord-xfce-terminal#
  • arcticicestudio/nord-xresources#
  • arcticicestudio/nord#
  • arcticicestudio/remark-preset-lint-arcticicestudio#
  • arcticicestudio/snowsaw#
  • arcticicestudio/styled-modern-normalize#
  • arcticicestudio/styleguide-java#
  • svengreb/styleguide-javascript#39
  • svengreb/styleguide-markdown#20
  • svengreb/website#

Initial style guide and project documentation

Add the initial commit message style guide and project documentation.

  • CHANGELOG header
  • Project assets
  • README section Introduction
  • README section Structural Split of Changes with Bad Practices
  • README section Commit Messages with Elements and their Structure including all components

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.