Git Hook

1 분 소요

title: what is git hook?

categories: - modernSoftware —

git hook이란??

Certainly! Git hooks are scripts that can be executed automatically before or after certain events occur in a Git repository. These events can include actions like committing changes, pushing to a remote repository, merging branches, or even checking out files.

git hook == 스크립트
저장소에 이벤트가 발생했을때 자동으로 수행되는 스크립트다.
이벤트라함은 커밋이된다던지, remote에 push가된다던지 merging이된다던지 그런 이벤트들을 이야기한다.

파일위치 (훅 파일위치)

Git hooks are stored in the .git/hooks directory within your Git repository. To utilize hooks, you need to create executable scripts in the programming language of your choice and place them in this directory. Git will then automatically execute these scripts at the appropriate times.

${projectRoot}/.git/hooks

사용자가 programming lang을 직접 골라서 별도로 스크립트를 작성 후 해당디렉토리로 옮겨놓으면
깃이 이벤트가 발생할 때 마다 스크립트가 수행.

훅 종류

1. Client side hook

Client-side hooks: These hooks reside in your local repository and are triggered by actions you perform on your local machine, such as committing changes or merging branches. Examples of client-side hooks include pre-commit, which is executed before a commit is made, and post-merge, which runs after a merge is completed.

local Repo에 이벤트가 발생했을 때 수행되는 훅. (commit or merging in local not remote)
pre-commit 과 post-merge로 구성되어있음.
pre-commit 은 commit 이 실행되기 전의 처리
post-merge 는 병합이 되고나서의 후 처리

2. Server side hook

Server-side hooks: These hooks are executed on the remote repository when certain actions are performed, like when someone pushes changes to the repository. Server-side hooks are useful for enforcing policies or performing actions that need to be applied consistently across all contributors. Common examples include pre-receive, which runs before accepting a push, and post-receive, which executes after a push is received.

remote Repo에 이벤트가 발생했을 때 실행되는 훅. (push …)
pre-receive 와 post-receive로 구성.
pre-receive == push 가 accepting되기 전의 처리
post-receive == push 후의 처리

사용목적

Git hooks enable you to automate various tasks, such as code formatting, running tests, enforcing coding standards, or triggering deployment processes. They can be written in any programming language, allowing you to customize your workflow to meet your specific needs.

음.. 주 사용목적은 git 이벤트가 발생하기전/후 에 자동으로 수행하는 스크립트.
코드를 포매팅한다던지 혹은 테스트를 한다던지?
대충 필터의 개념으로 이해하면 될듯함.

업데이트: