DEV Community

Cover image for Git Hooks: The Powerful Tool You're Probably Not Using (But Should Be)

Git Hooks: The Powerful Tool You're Probably Not Using (But Should Be)

Chiamaka Ojiyi on March 26, 2023

Introduction Git tops the list of version control software, allowing developers to collaborate and keep track of changes to source code....
Collapse
 
chubbystrings profile image
Emeka Okwor

Nice article chi, but how can you initialize this git/hook on your project? do I just create a directory for it or what? or is there a command to scafold git hook?

Collapse
 
algodame profile image
Chiamaka Ojiyi

Thank you Emeka. Git hooks are built into every project that has git initialized. So you already have git hooks available in your project. It is inside the .git/hooks folder in the .git directory. Since it hidden, you'll have to set your vscode to unhide hidden folders. You'll see the git hooks then. You can then overwrite the default code in any of the hooks to suit your needs.
Image description

Collapse
 
okpainmo profile image
Andrew James Okpainmo

Try out husky. It gives you hooks, with less hassle.

Collapse
 
wkylin profile image
wkylin.w

Using the VS Code toolbar go to ‘Code’ > ‘Preferences’ > ‘Settings’ and search for ‘exclude’ and you will find the default exclude list. Notice how this can be configured for the current user or the current workspace.

Thread Thread
 
algodame profile image
Chiamaka Ojiyi

Thank you for reading and sharing that tip.

Collapse
 
vastrolorde profile image
Seun Daniel Omatsola

Nice One Thanks

Collapse
 
algodame profile image
Chiamaka Ojiyi

Thank you Seun.

Collapse
 
okpainmo profile image
Andrew James Okpainmo

Great write up sis. But I guess going the git route complicates things too much. I'll rather recommend using Husky hooks. I've been using Husky for some good time now, and it integrates very easily with git.

Husky Is perfect I guess.

Collapse
 
algodame profile image
Chiamaka Ojiyi

Thank you for reading, Andrew. Yes, husky simplifies using git hooks in Nodejs projects. I use it at work too. However, I wanted to delve into the bare bones of git hooks. Thanks for commenting.

Collapse
 
akinloludavid profile image
akinloludavid

Really insightful article

Collapse
 
algodame profile image
Chiamaka Ojiyi

Thank you very much.