Search⌘ K

A ‘pre-commit’ Hook

Explore how to create and use a pre-commit hook in Git to automate workflow rules. This lesson helps you set up scripts that can prevent commits based on custom conditions, enhancing your control over repository changes.

Create repositories

To understand Git hooks properly, you’re going to create a bare repository with nothing in it and then clone from that bare repo. You looked at bare repositories earlier in this (advanced) part.

1	mkdir lgthw_hooks
2	cd lgthw_hooks
3	mkdir git_origin
4	cd git_origin
5	git init --bare
6	cd ..
7	git clone git_origin git_clone
Terminal 1
Terminal
Loading...

You have two repositories: git_origin (which is the bare repository you will push to) and git_clone (which is the repository you will work in). You can think of ...