Skip to main content

Command Palette

Search for a command to run...

Day 34: Git Hook Automation | 100 Days of DevOps

Updated
2 min read
R
I’m currently working in DevOps and documenting my learning journey along the way. From CI/CD pipelines to cloud and containers, I’m exploring how modern systems are built and deployed. This blog is where I share what I learn, break down concepts in simple terms, and track my progress. Learning one concept at a time, and trying to apply it practically.

Content:

Today I worked on implementing a Git hook to automate release tagging in a repository. The task involved merging branches, creating a post-update hook in a bare repository, and ensuring that a release tag is automatically generated whenever changes are pushed to the master branch.


🔹 What I Learned

  • What Git hooks are and how they automate workflows
  • How the post-update hook works after a push
  • How to dynamically generate tags using the system date
  • How to test hooks by triggering them with a push

Steps I Followed

1. Connected to Storage Server

ssh natasha@ststor01
sudo su

2. Navigated to the Repository

cd /usr/src/kodekloudrepos
ls
cd apps

3. Checked Available Branches

git branch

Observed:

  • feature
  • master

4. Switched to Master Branch

git switch master

5. Merged Feature Branch

git merge feature

Observed:

  • Fast-forward merge completed
  • feature.txt added to master

6. Created Git Hook (post-update)

vi /opt/apps.git/hooks/post-update

Added script:

#!/bin/bash

cd /opt/apps.git || exit

tag="release-$(date +%F)"

/usr/bin/git tag $tag
/usr/bin/git push origin $tag

7. Made Hook Executable

chmod +x /opt/apps.git/hooks/post-update

8. Pushed Changes to Trigger Hook

git push

Observed:

  • Push to master completed
  • Hook executed automatically

9. Verified Tag Creation

git fetch --tags
git tag

Observed:

  • Tag created successfully:

    release-2026-04-28
    

🔹 My Understanding

This task helped me understand how Git hooks can automate repetitive tasks like release tagging. By using a post-update hook in the bare repository, I was able to ensure that every push to the master branch automatically generates a release tag with the current date. This reduces manual effort and enforces consistency in versioning.


🔹 What I Found Interesting

I found it interesting how Git hooks run on the server-side repository and can control workflows after events like push. Automating tag creation using a simple script and system date felt powerful, and it showed how DevOps practices can streamline release management.


📌 Full notes: GitHub link