Git Hooks

repo: compscilauren/awesome-git-hooks
category: Development Environment related: Git Add Ons


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. Also, if you don't find the script you want below, you can create a new issue to request it.

Contents

Git Hook Scripts

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

icon language
<img width="14" src="bash-icon.png" alt="Bash Icon"> bash
<img width="14" src="python-icon.png" alt="Python Icon"> python
<img width="14" src="perl-icon.png" alt="Perl Icon"> perl

commit-msg

  • enforce-insert-issue-number - Make sure user did not delete the ISSUE-[#] string that was generated by prepare-commit-msg/insert-issue-number.hook. <img width="14" src="python-icon.png" alt="Python Icon">

post-checkout

  • delete-pyc-files - Delete all .pyc files every time a new branch is checked out. <img width="14" src="python-icon.png" alt="Python Icon">
  • new-branch-alert - Display a message when a new branch is checked out for the first time. <img width="14" src="bash-icon.png" alt="Bash Icon">

post-update

  • update-server-info - Prepare a packed repository for use over dumb transports (e.g. http). <img width="14" src="bash-icon.png" alt="Bash Icon">

pre-commit

  • dotenvx - Prevent committing your .env file(s) to code. <img width="14" src="bash-icon.png" alt="Bash Icon">
  • format-code - Run command to format code and re-add any files modified after formatting. <img width="14" src="bash-icon.png" alt="Bash Icon">
  • search-term - Fail commit if a specific term is found in the code. <img width="14" src="bash-icon.png" alt="Bash Icon">
  • spell-check-md-files - Check files with .md extension for spelling errors. <img width="14" src="bash-icon.png" alt="Bash Icon">
  • verify-name-and-email - Fail commit if user.name or user.email is incorrect. <img width="14" src="bash-icon.png" alt="Bash Icon">

prepare-commit-msg

  • include-git-diff-name-status - Include the output of "Git diff --name-status -r" into the message, just before the "Git status" output. <img width="14" src="bash-icon.png" alt="Bash Icon">
  • insert-issue-number - Insert issue number to beginning of the commit message. <img width="14" src="python-icon.png" alt="Python Icon">

pre-push

  • prevent-bad-push - Prevent push of commits where the log message starts with "WIP" (work in progress). <img width="14" src="bash-icon.png" alt="Bash Icon">

pre-rebase

  • prevent-rebase - Prevent topic branches that are already merged to 'next' branch from getting rebased, because allowing it would result in rebasing already published history. <img width="14" src="bash-icon.png" alt="Bash Icon">

query-watchman

  • fsmonitor-watchman - Output to stdout all files that have been modified since a given time. <img width="14" src="perl-icon.png" alt="Perl Icon">

update

  • update - Block unannotated tags from entering. <img width="14" src="bash-icon.png" alt="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
  1. Open your new file and paste the code from the hook you chose out of this repo (eg: verify-name-and-email.hook).
  2. Save file. Done! Now the Git hook will be triggered automatically.

Tools

  • Husky - Manage Git hooks with a nice user interface.

  • Overcommit - A fully configurable and extendable Git hook manager.

  • Git Build Hook Maven Plugin - Install Git hooks and config during a Maven build.

  • CaptainHook - Git hooks manager for PHP developers.

  • pre-commit - A framework for managing and maintaining multi-language pre-commit hooks.

Written Guides

Video Guides

License

CC0<br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/1.0/">Creative Commons Attribution 1.0 International License</a>.

[[curator]]
I'm the Curator. I can help you navigate, organize, and curate this wiki. What would you like to do?