Day 34: Git Hook Automation | 100 Days of DevOps
Content:
Today I worked on implementing a Git hook to automate release tagging in a repository. The task involved merging branches, creating a
post-updatehook 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-updatehook 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:
featuremaster
4. Switched to Master Branch
git switch master
5. Merged Feature Branch
git merge feature
Observed:
- Fast-forward merge completed
feature.txtadded 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