Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/CompSciLauren/awesome-git-hooks

:anchor: A curated list of awesome git hooks
https://github.com/CompSciLauren/awesome-git-hooks

List: awesome-git-hooks

automation awesome awesome-list bash git hooks script

Last synced: 15 days ago
JSON representation

:anchor: A curated list of awesome git hooks

Awesome Lists containing this project

README

        



Awesome Git Hooks

Awesome Git Hooks


Awesome Lists
PRs welcome

# Awesome Git Hooks

> :anchor: Easy-to-use git hooks for automating tasks during git workflows.

Git hooks are custom scripts you can use to automate tasks which are triggered before or after a git command is executed. There are two groups of these hooks: client-side and server-side. Client-side hooks are triggered by operations such as committing and merging, while server-side hooks run on network operations such as receiving pushed commits. This repo contains helpful resources as well as a variety of git hook scripts that can be easily customized to serve different purposes.

:heavy_check_mark: Nothing to install/download

:heavy_check_mark: Code is well-documented

:heavy_check_mark: Grab & go! Copy the code you want to use and paste into your .git/hooks folder

Contributions are _always_ welcome! Please see our [Contribution Guidelines](CONTRIBUTING.md). Also, if you don't find the script you want below, you can [create a new issue](https://github.com/CompSciLauren/awesome-git-hooks/issues/new?assignees=&labels=enhancement&template=new-git-hook-script-request.md&title=) to request it.

## Contents

- [Git Hook Scripts](#git-hook-scripts)
- [commit-msg](#commit-msg)
- [post-checkout](#post-checkout)
- [post-update](#post-update)
- [pre-commit](#pre-commit)
- [prepare-commit-msg](#prepare-commit-msg)
- [pre-push](#pre-push)
- [pre-rebase](#pre-rebase)
- [query-watchman](#query-watchman)
- [update](#update)
- [Quick Start](#quick-start)
- [Tools](#tools)
- [Written Guides](#written-guides)
- [Video Guides](#video-guides)

## Git Hook Scripts

Note: The icon next to each script signifies what language it is written in.

| icon | language |
| -------------------------------------------------------- | -------- |
| Bash Icon | `bash` |
| Python Icon | `python` |
| Perl Icon | `perl` |

### commit-msg

- [enforce-insert-issue-number](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/commit-msg-hooks/enforce-insert-issue-number.hook) - Make sure user did not delete the ISSUE-\[#] string that was generated by prepare-commit-msg/insert-issue-number.hook. Python Icon

### post-checkout

- [delete-pyc-files](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/post-checkout-hooks/delete-pyc-files.hook) - Delete all .pyc files every time a new branch is checked out. Python Icon
- [new-branch-alert](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/post-checkout-hooks/new-branch-alert.hook) - Display a message when a new branch is checked out for the first time. Bash Icon

### post-update

- [update-server-info](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/post-update-hooks/update-server-info.hook) - Prepare a packed repository for use over dumb transports (e.g. http). Bash Icon

### pre-commit

- [dotenvx](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-commit-hooks/dotenvx.hook) - Prevent committing your `.env` file(s) to code. Bash Icon
- [format-code](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-commit-hooks/format-code.hook) - Run command to format code and re-add any files modified after formatting. Bash Icon
- [search-term](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-commit-hooks/search-term.hook) - Fail commit if a specific term is found in the code. Bash Icon
- [spell-check-md-files](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-commit-hooks/spell-check-md-files.hook) - Check files with .md extension for spelling errors. Bash Icon
- [verify-name-and-email](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-commit-hooks/verify-name-and-email.hook) - Fail commit if user.name or user.email is incorrect. Bash Icon

### prepare-commit-msg

- [include-git-diff-name-status](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/prepare-commit-msg-hooks/include-git-diff-name-status.hook) - Include the output of "git diff --name-status -r" into the message, just before the "git status" output. Bash Icon
- [insert-issue-number](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/prepare-commit-msg-hooks/insert-issue-number.hook) - Insert issue number to beginning of the commit message. Python Icon

### pre-push

- [prevent-bad-push](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-push-hooks/prevent-bad-push.hook) - Prevent push of commits where the log message starts with "WIP" (work in progress). Bash Icon

### pre-rebase

- [prevent-rebase](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/pre-rebase-hooks/prevent-rebase.hook) - Prevent topic branches that are already merged to 'next' branch from getting rebased, because allowing it would result in rebasing already published history. Bash Icon

### query-watchman

- [fsmonitor-watchman](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/query-watchman-hooks/fsmonitor-watchman.hook) - Output to stdout all files that have been modified since a given time. Perl Icon

### update

- [update](https://github.com/CompSciLauren/awesome-git-hooks/blob/master/update-hooks/prevent-unannotated-tags.hook) - Block unannotated tags from entering. Bash Icon

## Quick Start

1. Pick a hook, any hook! Try the "verify-name-and-email" one if you're not sure where to start.
2. Navigate to your project's hooks folder (.git/hooks).
3. You should see a list of files already in there. Create a new file called the exact commit type that you want to use (eg: "commit-msg", "pre-rebase", "pre-commit", etc). Do not give it an extension.

![create new file](create-new-file.gif)

4. Open your new file and paste the code from the hook you chose out of this repo (eg: [verify-name-and-email.hook](https://github.com/CompSciLauren/git-hooks/blob/master/pre-commit-hooks/verify-name-and-email.hook)).
5. Save file. Done! Now the git hook will be triggered automatically.

## Tools

- [Husky](https://github.com/typicode/husky) - Manage git hooks with a nice user interface.

- [Overcommit](https://github.com/sds/overcommit) - A fully configurable and extendable git hook manager.

- [Git Build Hook Maven Plugin](https://github.com/rudikershaw/git-build-hook) - Install Git hooks and config during a Maven build.

- [CaptainHook](https://github.com/CaptainHookPhp/captainhook) - Git hooks manager for PHP developers.

- [pre-commit](https://github.com/pre-commit/pre-commit) - A framework for managing and maintaining multi-language pre-commit hooks.

## Written Guides

- [Git hooks documentation at git-scm.com](https://git-scm.com/docs/githooks)

- [Git Pro book by Scott Chacon and Ben Straub](https://git-scm.com/book/en/v2)

- [An Introduction to Git Hooks](https://www.sitepoint.com/introduction-git-hooks/)

- [Atlassian Tutorial on Git Hooks](https://www.atlassian.com/ru/git/tutorials/git-hooks)

- [Easy git hooks with husky](https://www.vojtechruzicka.com/githooks-husky/)

- [Git Hooked](https://www.javascriptjanuary.com/blog/git-hooked 'Git Hooked')

- [How To Use Git Hooks To Automate Development and Deployment Tasks](https://www.digitalocean.com/community/tutorials/how-to-use-git-hooks-to-automate-development-and-deployment-tasks)

- [Automate Your Workflow with Git Hooks](https://hackernoon.com/automate-your-workflow-with-git-hooks-fef5d9b2a58c)

- [Using JavaScript in Your Git Hooks](https://medium.com/@Sergeon/using-javascript-in-your-git-hooks-f0ce09477334 'Using JavaScript in Your Git Hooks')

- [An In-Depth Look at Git Hooks](https://dzone.com/articles/an-in-depth-look-at-git-hooks)

- [Git hooks and practical uses. Yes, even on Windows.](https://www.tygertec.com/git-hooks-practical-uses-windows/)

- [Automatically Manage Git Hooks with Direnv](https://knpw.rs/blog/direnv-git-hooks)

## Video Guides

- [Git Hooks Part 1 - Getting Started](https://www.youtube.com/watch?v=aB3eq52sZSU)

- [Git hooks and practical uses. Yes, even on Windows.](http://www.youtube.com/watch?feature=player_embedded&v=fMYv6-SZsSo&t=140s)

## License

[![CC0](http://mirrors.creativecommons.org/presskit/buttons/88x31/svg/cc-zero.svg)](https://creativecommons.org/publicdomain/zero/1.0/)
This work is licensed under a Creative Commons Attribution 1.0 International License.