Skip to content

Reusable Git hook templates for enforcing safe and consistent workflows across repositories. Includes scripts to prevent direct pushes to main, install hooks automatically, and standardize local development practices for students and collaborators.

Notifications You must be signed in to change notification settings

intelligent-control-lab/git-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧩 git-hooks

Reusable Git hook templates to help enforce safe and consistent workflows across repositories.
These hooks prevent accidental pushes to main and encourage the use of feature branches and pull requests.


πŸš€ Features

  • Pre-push protection: Blocks direct pushes to main.
  • Easy installation: One-step setup script copies and activates all hooks locally.
  • Reusable design: Can be added as a submodule to any repository.

βš™οΈ Setup Options

πŸ”Ή Add as a Git Submodule (for the repository administrator)

To reuse these hooks across multiple repositories, the repository administrator should set up the submodule once:

git submodule add [email protected]:intelligent-control-lab/git-hooks.git git-hooks
git add .gitmodules git-hooks
git commit -m "Add git-hooks submodule"
git push

After this initial setup, the link between your main repository and the git-hooks submodule is saved permanently.

🧩 On Future Clones (for the administrator or developers)

Anyone who later clones the main repository only needs to run:

git submodule update --init --recursive
cd git-hooks
./install-hooks.sh

No need to run git submodule add again β€” that command is only required the first time when the administrator sets up the submodule.

πŸ§ͺ Test Your Setup

  1. Switch to main and try pushing:
git checkout main
git push

You should see:

🚫 Direct pushes to main are not allowed.
Please create a feature branch.
  1. Now create a feature branch:
git checkout -b feature/test
git push --set-upstream origin feature/test

The push should succeed normally.

🧰 Repository Structure

git-hooks/

β”œβ”€β”€ pre-push # Hook script that blocks direct pushes to main

β”œβ”€β”€ install-hooks.sh # Installation script for local setup

└── README.md # This file

πŸ’‘ Notes

β€’	The hooks live locally (under .git/hooks) and are not committed with your project.

β€’	If you reclone or reset your repository, re-run install-hooks.sh.
β€’	You can extend this repo with more hooks (e.g., lint checks, test runners, etc.) as your workflow grows.

About

Reusable Git hook templates for enforcing safe and consistent workflows across repositories. Includes scripts to prevent direct pushes to main, install hooks automatically, and standardize local development practices for students and collaborators.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages