Git Style Guide
Kedar Kulkarni
?? Architect UI | JavaScript Enthusiast | ReactJS | EmberJS | Docker | RestAPI | Open Source | ChatBot & NLP Enthusiast | Open to Work | Talks about #brand, #change, #business, #innovation, #leadership #growth
Table of contents
Branches
The main repository will always hold two evergreen branches:
The main branch should be considered origin/master and will be the main branch where the source code of HEAD always reflects a state with the latest delivered development changes for the next release. As a developer, you will be branching and merging from master.
Consider origin/stable to always represent the latest code deployed to production. During day-to-day development, the stable branch will not be interacted with.
When the source code in the master branch is stable and has been deployed, all of the changes will be merged into stable and tagged with a release number. How this is done in detail will be discussed later.
Pattern
Git Branching Strategies
Apart from having good Git Branching Strategies, it is important to follow some naming conventions to ensure proper maintenance of the repository and a clear, structured way of separating tasks. To avoid confusion and have an organised overview of every feature that is being worked on, we go through seven best practices for naming branches.
# good
$ git checkout -b fix/oauth-migration
# bad - too vague
$ git checkout -b login_fix
# GitHub issue #15
$ git checkout -b fix/issue-15-short-title
$ git checkout -b feature/new-feature # good
$ git checkout -b feature/T321-new-feature # good (Phabricator task id)
$ git checkout -b New_Feature # bad
$ git checkout -b feature-a/main # team-wide branch
$ git checkout -b feature-a/maria # Maria's personal branch
$ git checkout -b feature-a/nick # Nick's personal branch
Merge at will the personal branches to the team-wide branch (see "Merging"). Eventually, the team-wide branch will be merged into "main" / "master".
Tip: Use the following command while being on "main", to list merged branches:
领英推荐
$ git branch --merged | grep -v "\*"Summary
Workflow Diagram
General Commit Guidelines
When committing code, follow these general guidelines:
$ git diff --check
Writing Commit Messages
For writing commit messages, adhere to the following rules to enhance the clarity and traceability of your commits, making it easier for collaborators to understand your code changes and for automated systems to manage issues and pull requests effectively.
To link commits to GitHub Issues, include one or more issue numbers in the commit message, and optionally, specify a state change for the story. Start the commit message with square brackets containing a hash mark followed by the issue number, like this:
[#123] Diverting power from warp drive to torpedoes
To automatically close an issue with a commit message, add "Closes" within the square brackets along with the issue number, as in:
[Closes #123] Torpedoes now sufficiently powered
Note: While there are multiple ways to close an issue via a commit message, "Closes" is the recommended standard. Other options include:
You can also enclose multiple issue numbers within brackets and combine actions with commit tracking, like this:
[Closes #123][#124][#125] Torpedoes now sufficiently powered
This example would close issue 123 and add commit references to issues 124 and 125 for tracking purposes.
Commit Message Template
Here's a suggested commit message template, inspired by Tbaggery's blog post:
[<optional state> #issueid] (50 chars or less) Summary of changes
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so.
Further paragraphs come after blank lines.
- Bullet points are okay, too.
- Typically, use a hyphen or asterisk as the bullet, preceded by a single space, with blank lines in between. Conventions may vary.
References