Thomas Burleson
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: GitOps - Top 10 Rules description: Top 10 Rules for Best Git Processes tags: git, best practices, 10 Rules lang: en --- ![](https://i.imgur.com/JcJo9n8.png) > Authors: > * [Thomas Burleson](mailto:thomasburleson@gmail.com), Solutions Architect > * Copyright 2021 - All rights reserved > <br> # GitOps: Top 10 Rules <br> ![](https://i.imgur.com/D5Ypxex.png) <br> Using Git properly is essential for successful web-application development and CI/CD. The best practices for GitFlow have been codified and condensed into **10 Essential Rules**: 1. [Use **GitFlow** strategies](#(1)-Use-GitFlow-Strategy) 2. [Use **Locked** Branches](#(2)-Use-Locked-Branches) 3. [**Rebase** Often](#(3)-Rebase-Often) 4. [Use **Fast-Forward** Merge](#(4)-Use-Fast-Forward-Merge) 5. [Use Commit **Conventions**](#(5)-Use-Commit-Conventions) 6. [Use a **Code Review** process](#(6)-Require-a-Code-Review-process) 7. [Improve your **Log History**](#(7)-Use-Rebase-for-Improved-Git-Logs) 8. [Don't commit **Dependencies**](#8-Don%E2%80%99t-commit-Dependencies) 9. [Use **Prettier**](#(9)-Use-Prettier) 10. [Use **README**(s)](#(10)-Use-README(s)) These ^ rules are sorted in highest priority and are detailed in the following sections. <br/> :::info :bulb: **Hint:** Click a link above to speed-jump to the details for that rule. ::: <br/> ## (1) Use GitFlow Strategy Unlike [Trunk-based Git](https://www.toptal.com/software/trunk-based-development-git-flow) development, the **Gitflow** workflow defines strict branching models designed around pull-requests and multi-team project releases. [![](https://i.imgur.com/Hz1lZLd.png)](https://i.imgur.com/Hz1lZLd.png) ##### Main branches * `origin/master` is the main branch where the source code of HEAD always reflects the current *production-release*. * `origin/develop` is the main development branch where the source code of HEAD always reflects the latest integrated development changes; ready for the next QA release. Some would call this the “integration branch”. > This is where any automatic nightly builds are built from. * `origin/release` is the QA branch used to perform acceptance, end-2-end testing, and other checks required before production release. When changes are merged back into `origin/master`, this is a *new production release* by definition. This should be very strict process in which a Git hook script is used to **automatically build and roll-out to the production servers** everytime there is a commit on `origin/master`. Only by using Pull-Requests can code be committed to `origin/master`... and only from the `origin/release` or `origin/hotfixes` branches. The Git repository settings should require production-release-manager approval to merge PRs into master. ##### Feature branches * `origin/feature/<xxx>` are the branches in which all sprint work is performed. Feature-work changes can only be merged into `origin/develop` with **Pull Requests**. Long-lived feature branches should follow rule [(3) Rebasing Often](#(3)-Rebase-Often). * Automated CI will not triggered/performed on Feature branches. * Automated CI tests will be triggered for all Pull Requests. * Developers are not allowed to push commits direct to `origin/master`, `origin/develop`, or `origin/release`. :::warning :bulb: All developers should use the same repository for feature-based work. Developers should not fork the repository. While *Forking* provides significant upstream repository-benefits, the *origin + upstream* relationships complicates feature-based development. ::: [![](https://i.imgur.com/4PKB2Sf.png)](https://i.imgur.com/4PKB2Sf.png) <br/> ## (2) Use Locked Branches All developer sprint-work will be performed in the `origin/feature/<xxx>` branches (or `origin/hotfixes`). Only these two (2) branches will support direct-push commits. To enforce the **Merge by Pull-Request** process, the branches `master`, `develop`, and `release` should be locked to prevent direct push commits. [![](https://i.imgur.com/dM8g82D.png)](https://i.imgur.com/dM8g82D.png) * All developer changes are restricted to `origin/feature/**` or `origin/hotfix/**` * Only `origin/feature/**` & `origin/hotfix/**` branches support direct commit pushes * All other branches require Pull Request processes to add commits (merges with squash, fast-forward) <br/> ## (3) Rebase Often Developers should **always** use `git pull --rebase origin <branch>` to insert all *origin* changes below the timeline of their current changes. ![](https://i.imgur.com/IXJ6FlX.png) > Developers can also use `git rebase <with-source-branch>` to rebase with a local branch (instead of the remote `origin`). <br/> For feature-based work, the local feature-branch should be rebased (a) *daily* and (b) *before all updates* to the `origin` PR branch. The following commands should be used: * `git pull --rebase origin develop` ...to update local code with origin changes. * `npm run build & npm test:affected & npm run lint` ...to confirm everything is still working. :::danger To reduce local development friction, teams may elect to merge all PRs with automated `rebase, squash, and fast-forward` merges. The negative impact of this automation will limit each PR to one (1) single commit. As such, this approach is not recommended. ::: :::success Feature branches can rebase locally: **`git pull --rebase origin develop`**. ::: #### Conflicts Rebasing will inevitably produce conflicts that must be resolved. This is especially true for branches with many "change" commits. To reduce conflict-friction, developers should **FIRST** squash their *new* commits to 1..n logical commits. > If you do not want to customize the squash process then use `git pull --rebase --autosquash origin/<branch>`. Squashing your own commits should facilitate conflict resolution when a `git pull --rebase <branch>` is susbsequently used. ---- Since rebase rewrites the target branch SHA history *below* your current branches changes... a `git push -f` will be required to update the remote `origin` branch. ---- #### Summary Rebasing ensures that your feature changes are based on ALL current `origin/develop` changes. * All Pull Requests should be rebased locally before pushing updates (to the PR branch). * After rebasing: 1. Locally perform a full cycle of 'build, test, lint' 2. Must use **`git push -f origin <branch>`** to force push your rebased changes. 3. CI will auto-run the same when the associated PR is updated. <br> :::danger :fire: **Important**: Force pushing should **ONLY** be used for your PR branch. ::: :::warning Full details: **[Pull-Request Best Practices]()** (pending) ::: <br/> ## (4) Use Fast-Forward Merge Your Pull Request has been rebased, commits squashed, pushed to `origin`, and all CI tests and checks are passing. After code reviews, reviewer approvals and LGTMs... it is time to merge your PR to `origin/develop`. [![](https://i.imgur.com/H5ghBdu.png)](https://i.imgur.com/H5ghBdu.png) A Fast-Forward merge will ensure that `origin/develop` retains a flat commit history... without any cluttering 3-way merge information. Because this FF-M strategy moves the PR branch's commits to the `origin/develop` branch, you'll still see all commits on the Commits page. > Using "Fast-Forward Merge" supports PRs with more than 1 commit. This is another reason for authors to properly squash their commits to a logic set. #### After the PR Merge... The repository settings should be set to auto-archive the `origin` branch associated with a merged PR. Developers should also perform the following three (3) steps to update their local repository branches: 1. Checkout the `develop` branch: **`git checkout develop -f`** 2. Update `develop` with the latest `origin` version: **`git pull --ff origin master`** 3. Delete the local PR branch: **`git branch -D <PR branch>`** <br/> ## (5) Use Commit Conventions #### Why are conformance to Commit Conventions critical? Development best practices use processes to auto-generate Release ChangeLogs from the commit history. And **commit conventions** are the key to ChangeLog auto-generations. e.g. [![](https://i.imgur.com/6Aw1iGy.png)](https://i.imgur.com/6Aw1iGy.png) Commit conventions promote *concise, contextual commit messages* that are easy to scan in change logs and project history. Using commit conventions [with squashing + rebasing], your Git Log history will be succinct and easy to manage. e.g. [![](https://i.imgur.com/pRvFJfw.png)](https://i.imgur.com/pRvFJfw.png) #### Commit Convention Details The recommed conventions follow Google's *Angular Guidelines* regarding git commit message formats. Use the link below to jump to the Appendix section for full details: :::info :bulb: Full details: **[Commit Conventions](#-Commit-Message-Conventions)** ::: <br/> ## (6) Require a Code Review process A proper code review insures quality and provides a great mentoring opportunity. Code changes are merged into `origin/develop` only with Pull Requests ![](https://i.imgur.com/PKk7tWp.png) Before a code review is started, the PR should include: * An initial label `PR: Ready for Review` * A PR body has **clear description** (images optional) * A PR body with reference to **Jira issue** & other reference links. * Code rebased from `origin/develop` * Commits squashed to 1 or more logical commits * At least 1 person (2 preferred) requested to review * All CI processes passing: ( build, tests, e2e, lint ) * Assign CodeOwners and require review sign-off on PRs All Pull Requests must have reviewer approval before a PR is ready for merge. PR Authors are **never allowed** to merge their own PRs. Reviewers should avoid subjective criticisms and attempt to provide all feedback in a single review pass. After Code Reviews, approvals and LGTMs, it is time to merge your PR to `origin/develop`. :::warning :bulb: Full details: **[Git Code Reviews]()**. (pending) ::: <br/> ## (7) Improved Git Logs Developers want terminal tools to view log history in concise, compacted formats. With traditional **merge** or **pull** approaches, the Git timeline gets distorted and polluted with unwanted merge information. Repository log history can produce radically different outputs. ```bash git lg # show compact history ``` Here is project history for teams **NOT** following best practices: ![](https://i.imgur.com/NX01Ffe.png) Here the team is following bes practices: Rebasing, Squash, and Commit Conventions. These all work togehter to ensure the git history will be flat, clean, and concise. ![](https://i.imgur.com/soicP2u.png) A flat timeline (eg commit history) is another important factor to the auto-generation of ChangeLogs. Notice how the use of [Commit Conventions](#(7)-Use-Commit-Conventions) helps create a clear, concise log history (above). :::info :bulb: Full details: [**Customizing your Git Log**](#Customized-Git-Logs) ::: <br/> ## (8) Don't commit Dependencies Always use a `.gitignore` file to exclude specific artifacts for *source control management*. :::info :bulb: Full Details here: [**Recommended .gitIgnore Settings**](#-gitignore-Settings) ::: <br> ## (9) Use Prettier Use prettier to auto-format all files during save. Use *Prettier* to minimize commit-change white noise. * Use **`nx format:write`** to format all files in project. * Enable **Format on Save** options in your IDE. Consistent use of Prettier will ensure your Pull Requests will only show diffs for content changes instead of style/format changes. ##### `.prettierrc` ```jsonld= { "singleQuote": true, "useTabs": false, "printWidth": 120, "tabWidth": 2 } ``` :::warning :bulb: Jump to: [**Prettier Options**](https://prettier.io/docs/en/options.html) ::: <br> ## (10) Use README(s) A Repository will have at least one (1) `README.md`... but may contain others for specific folders or packages. The intent for each README is to convey information (and images if available) to show the purpose of the repository, package, or directoy. > Do not use the default, generated README. README documents should be hyperlinked to support easy navigation. ![](https://i.imgur.com/5klO4el.png) Badges should be used in the root project README to highlight version, CI status, and more ![](https://i.imgur.com/TYFSOS1.png) <br> :::warning :bulb: Jump to: [**Badge Options**](https://img.shields.io). ::: <br> <br> <br> # Appendix Within this appendix are details for various options and recommendations * [Customized Git Logs](#Customized-Git-Logs) * [Commit Message Conventions](#-Commit-Message-Conventions) * [Developer Tooling](#Developer-Tools) * [`.gitignore` settings](#-gitignore-Settings)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully