Skip to content

baurine/git-hooks-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Git Hooks Sample

Sample for git hooks: pre-commit, prepare-commit-msg, commit-msg, written by ruby.

References

  1. Git钩子:自定义你的工作流
  2. Code Reviews with Rubocop and Git pre-commit hook
  3. pre-commit hooks

How to run

Make sure you have installed ruby.

Copy git-hooks/* to your git repo .git/hooks folder, add execute permission for them by chmod u+x.

Then if you commit code in a branch its name follows feature|bug|hotfix|misc|refactro/issue-num_content format, it will automatically pre-fill your commit message, for example, if the branch name is misc/123_fix_typo, it will automatically pre-fill your commit message by MISC #123 - Fix typo.

Pre-filling commit message only works in command console, doesn't work in tools with UI, likes SourceTree, GitUp.

And your commit message must follow the required format: FEATURE|BUG|MISC|REFACOTR #num - Content, else the commit will be rejected.

You can modified the hooks according to your need, supplied unit test to easily change rule.

Demo

  1. Pre commit hook, check code style:

  2. Prepare commit message hook, pre-fill some commit message:

  3. Commit message hook, check commit message format:

About

Sample for some git hooks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published