DevOps Classroom Series – 21/Feb/2021 (Evg)

Git Hooks

  • Git Hooks are scripts that run automatically every time a particular event occurs in Git Repository
  • Git Hooks are located in the .git/hooks Preview
  • Git Hooks call the scripts which can be in any scripting language
  • Git Hooks are of two types
    • Client Side Hooks:
      • These are executed on the commiter’s system
      • This can be further categorized as
        • Commiting workflow hooks
        • Email Workflow Hooks
        • Other
    • Server-Side Hooks: These are executed on the remote repository. These are divided into following categories.
      • Pre-receive and Post-receive hooks
      • Update
    • Server Side Hooks are the scripts which are executed on server, but if the organization is using cloud/hosted repositories like GitHub/Code Commit/ Azure Source Repos/Bit Bucket then web hooks are enabled.
  • Some of the popular hooks
    • applypatch-msg: Invoked by git am
    • pre-applypatch:
    • post-applypatch:
    • pre-commit: executed by git commit
    • prepare-commit-msg: executed by git commit
    • commit-msg: executed by git commit
    • post-commit: executed by git commit
    • pre-rebase
    • post-checkout: git checkout and git clone
    • post-merge: git merge and git pull
    • pre-push
    • pre-recieve
    • update
    • post-recieve
    • post-update
  • Sample pre-commit hook
echo " precommit"


  • With hooks whenever developer submits code we can execute functionality by calling hook scripts, So when developer submits code we can call
    • Jenkins to build
    • Ansible to deploy
    • Terraform to deploy
  • If you do these kind of activities where your pipeline is triggered as part of git hook it is also referred as git ops.
  • In the case of git hub we can configure web hooks and from there call the pipeline Preview

Git Branching Strategy

  • Refer Here
  • Per project:
    • Day builds: multiple times a day
      • Build the code, package the code, run unit tests, run sonar qube
    • Night builds: execute once in day:
      • Build the code, package the code, upload the package to artifactory
      • Run unit tests
      • Create test environments (run configuration management/infraprovisioning)
      • Run QA tests (Selenium/QTP)
      • Run Perf tests (Jmeter/Loadrunner)
    • Production builds: execute once per release

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin