What is GIT Hooks.

Git hooks are scripts those run automatically every time a specific event occurs in a Git repository. You can customize Git’s internal behavior and actions at key points in the development life cycle.

Here i am going to describe how can we change default behavior of hooks.

I am changing prepare-commit-msg  hook’s functionality .

These are following step :-

1- You can find default hooks available in directory  /repoName/.git/hooks/ .

2. Rename hook’s name from prepare-commit-msg-sample to prepare-commit-msg.

Default behavior of this hooks is  only display four parameter .

– Commit hash-code..

– Author Name .

– Date.

– Commit Message .

See following image for default behavior .

4 . Now what i want , I want to append branch name with commit message . For this i have to write following  script in  prepare-commit-msg file .

After overall editing my file will be look like this .

5 – From now whenever you will commit file ,you will get following type of log record with branch name .

Here you can see Branch name with commit message .