What Are Git Commit Hooks and What Can They Do for Us?

Some useful examples from real life

keypressingmonkey
Apr 15, 2020 · 3 min read
Image for post
Image for post
Photo by Efe Kurnaz on Unsplash.

What Is a Commit Hook?

Practical Use Cases

Sort imports alphabetically

Forbid unwanted files from being pushed to the repo

Forbid coworkers from pushing changes to a repo

Complain if images are too large

I have not built a hook like this yet, but this piece of magic apparently does just that. Git hook syntax is a completely new language on its own.

Honorable mention: Take a webcam picture each time you commit

The name of the repo is already great, but the content is even better. As I was loading it, I thought to myself, “Please, please have sample images.” And it didn’t disappoint.

Takeaway: Git Hooks Can Be Amazingly Useful

Better Programming

Advice for programmers.

Sign up for The Best of Better Programming

By Better Programming

A weekly newsletter sent every Friday with the best articles we published that week. Code tutorials, advice, career opportunities, and more! Take a look

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Thanks to Zack Shapiro

keypressingmonkey

Written by

Programmer by day, creative writer by night. Find me at https://codingtofreedom.com

Better Programming

Advice for programmers.

keypressingmonkey

Written by

Programmer by day, creative writer by night. Find me at https://codingtofreedom.com

Better Programming

Advice for programmers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store