:wq cheats/git-commits
Tags: awesome, cheatsheet, bestpractices, git
Published: 2023-09-13 19:30:15

## Git Commits

- [How to Write a Git Commit Message][1]
- [5 Useful Tips For A Better Commit Message][2]
- [Conventional Commits][3]
- [Atomic Git Commits][4]

**7 rules of a great Git commit message**

 - #1 Keep in mind: This has all been said before.
 - #2 Separate subject from body with a blank line
 - #3 Limit the subject line to 50 characters
 - #4 Capitalize the subject line
 - #5 Do not end the subject line with a period
 - #6 Use the imperative mood in the subject line
 - #7 Wrap the body at 72 characters
 - #8 Use the body to explain what and why vs. how

___

**Commit message structure**

```gitcommit
<type>[optional scope]: <Description>

[optional body]

[optional footer(s)]
```

#### Examples

Commit with description and breaking change footer

```gitcommit
feat: Allow provided config object to extend other configs

BREAKING CHANGE: `extends` key in config file is now used for extending other config files
```

Commit with ! to draw attention to breaking change

```gitcommit
feat!: Send email to the customer when product is shipped
```

Commit with scope and ! to draw attention to breaking change

```gitcommit
feat(api)!: Send email to the customer when product is shipped
```

Commit with both ! and BREAKING CHANGE footer

```gitcommit
chore!: Drop support for Node 6

BREAKING CHANGE: use JavaScript features not available in Node 6.
```

Commit with no body

```gitcommit
docs(CHANGELOG): Correct spelling
```

Commit with scope

```gitcommit
feat(lang): Add Polish
```

Commit with multi-paragraph body and multiple footers

```gitcommit
fix(requests): Prevent racing

Introduce a request id and a reference to latest request.

Also:
- Dismiss incoming responses other than from latest request.
- Remove timeouts which were used to mitigate the racing issue but are obsolete now.

Refs: #123
```

___

## Tooling

  - [Gitlint][5]
  - [Pre-commit][6]
  - [Semantic Release][7]

___

## References

  - [Pro Git book][0]
  - [Como fazer um commit semântico][8]
  - [Conventional Commits: Cheat Sheet][5]
  - [Git e Github na prática: Guia do iniciante][10]
  - [A guide to improve the Git(Hub) flow and commits messages][11]
  - [Git Flow vs GitHub Flow | Alex Hyett][12]
  - [What are the pros and cons of git-flow vs github-flow?][13]
  - [Choosing the Right Git Workflow for Your Project: GitFlow, GitHub Flow][14]
  - [Workflows Comparison: Git Flow Vs GitHub Flow - Fresh Consulting][15]
  - [Git(Hub) Flow, Trunk Based Development, and Code reviews][16]

[0]: https://git-scm.com/book/en/v2 "Pro Git book"
[1]: https://cbea.ms/git-commit "How to Write a Git Commit Message"
[2]: https://thoughtbot.com/blog/5-useful-tips-for-a-better-commit-message "5 Useful Tips For A Better Commit Message"
[3]: https://conventionalcommits.org/en/v1.0.0 "Conventional Commits: A specification for adding human and machine readable meaning to commit messages"
[4]: https://www.aleksandrhovhannisyan.com/blog/atomic-git-commits "Make Atomic Git Commits"
[5]: https://jorisroovers.com/gitlint/latest "Gitlint: Linting for your git commit messages"
[6]: https://pre-commit.com "Pre-commit: A framework for managing and maintaining multi-language pre-commit hooks"
[7]: https://semantic-release.gitbook.io/semantic-release "Semantic Release: Fully automated version management and package publishing"
[8]: https://blog.rocketseat.com.br/como-fazer-um-commit-conventional-commits "Como fazer um commit semântico"
[9]: https://kapeli.com/cheat_sheets/Conventional_Commits.docset/Contents/Resources/Documents/index "Conventional Commits Cheat Sheet"
[10]: https://youtube.com/watch?v=gQVUCTVt39o "Git e Github na prática: Guia do iniciante"
[11]: https://roalcantara.medium.com/a-guide-to-improve-the-git-hub-flow-and-commits-messages-b495461e1115 "A guide to improve the Git(Hub) flow and commits messages"
[12]: https://www.alexhyett.com/git-flow-github-flow "Git Flow vs GitHub Flow | Alex Hyett"
[13]: https://stackoverflow.com/questions/18188492/what-are-the-pros-and-cons-of-git-flow-vs-github-flow "What are the pros and cons of git-flow vs github-flow?"
[14]: https://medium.com/@vava_silva/choosing-the-right-git-workflow-for-your-project-gitflow-github-flow-and-gitlab-flow-6a12cb438ccb "Choosing the Right Git Workflow for Your Project: GitFlow, GitHub Flow"
[15]: https://www.freshconsulting.com/insights/blog/git-development-workflows-git-flow-vs-github-flow "Workflows Comparison: Git Flow Vs GitHub Flow - Fresh Consulting"
[16]: https://reviewpad.com/blog/github-flow-trunk-based-development-and-code-reviews "Git(Hub) Flow, Trunk Based Development, and Code reviews"