Using Git Hooks

preview_player
Показать описание
Git Hooks provide a way for you to hook into your local git installation and attach additional behavior to common git actions. For example: validating that your code builds during a commit, confirming git commit messages or running your test suite before pushing your code changes to your peers. Because git hooks run on your local machine and are not checked in with the rest of your code you can also use them to automate certain parts of your workflow that might be unique to you.

Note: Git Hooks are not a replacement for a CI/CD pipeline like GitHub Actions, CircleCI etc!

You can add a new Git Hook by adding a file to the `.git/hooks` directory of your project that matches one of the supported git hooks. The supported git hooks are:

* `pre-commit`
* `prepare-commit-msg`
* `commit-msg`
* `post-commit`
* `pre-push`
* `applypatch-msg`
* `pre-applypatch`
* `post-applypatch`
* `pre-rebase`
* `post-checkout`
* `post-merge`
* `post-update`
* `pre-auto-gc`
* `post-rewrite`

Files you change in the `.git` directory will not be checked into your git repository and therefore will not be visible to the rest of your team. If you'd like to share your pre-commit and other hooks with your team you can place the scripts somewhere inside your project and create a symlink to them in the `.git/hooks` directory.

Note: make sure that you make your Git Hooks executable or git will not be able to access and run them!

```json
"**/.git": false
},
```

This setting prevents all `.git` directories in your project - regardless of where they are located - from being hidden.

You can also bypass Git Hooks using the `--no-verify` (shorthand `-n`) argument when running git commands in your CLI. This will completely bypass these hooks and prevent them from running. If you have a Git Hook that requires tests to pass before pushing running `git push --no-verify` would allow you to push your changes for example.

Рекомендации по теме
Комментарии
Автор

Hi, I just want to Thank You for all your efforts. Whenever I start watching any of your Video, I just know that you'll explain it from each and every aspect. I've watched all of your Unity related videos. I know this channel is bit underrated but hey, there are still many people that love you for all your efforts. ❤
And your style of always being happy is lit. 🔥

sherazali
Автор

Great explanation brother keep it up and all the best :)

pavankumar
Автор

You look so good with the hair! Awesome vid :)

dudubroder
Автор

Thank you for very much for this video. You've got a new subscriber :). If you don't mind, I've got a few questions. I just learnt about ESLINT and am in the process of implementing it along with Prettier. Another video mentioned how we could Lint and Format our code using ESLINT + Prettier, prior to pushing it to a Github repository using Git Hooks. After reading a few articles, I came across your video. Many of the articles keep mentioning Husky, I went to their website and it says "Husky improves your commits and more 🐶 woof!", but I thought that's what's Git Hooks is doing... I would really appreciate it if you could help me by answering the following questions or make a video about them.
1) What can Husky do that Git Hooks can't?
2) If Husky doesn't add anything new to Git Hooks but only makes it easier to use Git Hooks, how does it do that?
3) Could you show us how to do that symlink so that our Git Hooks get pushed to our Repository?
4) Instead of having to recreate or copy/paste our Git Hooks, how would we go about having a global Git hooks folder that can be used for all projects?
5) Using Github Actions, is it possible to reject a push to a repository if it doesn't meet a certain criteria, let's say, because the code hasn't been run through ESLINT or Prettier?

Thank you a million times in advance!

Naz-yibs
Автор

I gave you like, but sorry i had to stop the video because you kind panicked when you talk, this happened when people didn't practice enough front of the cameras, anyway just relax and you will be great.
thank you for your video :)

leontalkdaliy