Introduction
Software development today is not just about writing code—it's about writing secure, reliable, and production-ready code. As applications become more complex, developers need automated mechanisms to catch security issues before they reach production.
During Week 4 – Assignment 6 of the DevOps Micro Internship (DMI), I explored how Git Pre-Commit Hooks, AI-assisted code reviews, and Agentic AI workflows work together to improve code quality. This assignment demonstrated that combining automation with AI can significantly strengthen the software development lifecycle while keeping humans in control of final decisions.
Why This Assignment Was Important
One of the most common mistakes developers make is accidentally committing:
Hardcoded credentials
API keys
Debug statements
Private keys
Large unnecessary files
Once committed, these artifacts become part of Git history and can pose serious security risks.
The goal of this assignment was to prevent such mistakes before the code is committed, using automation and AI-powered analysis.
Step 1: Starting with a Clean Git Workflow
The journey began by confirming the repository setup and creating a dedicated feature branch.
Instead of working directly on the main branch, a separate branch was created to isolate changes.
This simple practice offers several advantages:
Keeps the main branch stable
Makes collaboration easier
Produces cleaner Pull Requests
Reduces merge conflicts
Feature branching is one of the most widely adopted Git best practices in modern software development.
Step 2: Creating a Risky Script for Testing
To test automated security checks, a shell script named:
scripts/notify.sh
was intentionally created with two common security issues:
A hardcoded AWS-style access key
A debug statement exposing sensitive information
Although the values were placeholders, they closely resembled mistakes that developers accidentally introduce into repositories.
This setup provided a realistic scenario for validating security automation.
Step 3: Protecting the Repository with a Git Pre-Commit Hook
The core of this assignment involved creating a custom Git Pre-Commit Hook.
The hook automatically scanned staged files before every commit.
It performed two important checks:
Secret Detection
It searched for patterns matching:
AWS Access Keys
RSA/OpenSSH Private Keys
File Size Validation
It prevented files larger than 1 MB from being committed.
Whenever either rule was violated, Git immediately rejected the commit.
Instead of allowing risky code into the repository, developers received clear feedback about what needed to be fixed.
This demonstrated how automation can enforce security without requiring manual inspection every time.
Understanding Rule-Based Validation
A Git pre-commit hook follows predefined rules.
For example:
If an AWS key pattern is found → Block the commit.
If a staged file exceeds the allowed size → Reject the commit.
Advantages
Extremely fast
Consistent every time
Easy to automate
Excellent for known security risks
Limitation
It only detects patterns that have been explicitly programmed.
It cannot understand the intent or context behind the code.
Step 4: AI-Powered Review with /pr-ready
After implementing rule-based validation, the assignment introduced an AI-powered review skill called:
/pr-ready
Unlike the Git hook, this AI reviewer analyzed the staged changes much like an experienced code reviewer.
It evaluated:
Debug statements
Documentation gaps
Potential security concerns
Pull Request readiness
Overall code quality
Rather than simply blocking a commit, it explained why certain changes could become problems and even generated a draft Pull Request title and description.
This highlighted how AI can provide contextual insights beyond simple pattern matching.
Rule-Based Automation vs AI Code Review
Git Pre-Commit Hook AI Review (/pr-ready)
Pattern Matching Context Understanding
Fast and Consistent Human-like Reasoning
Detects Known Risks Explains Potential Issues
Blocks Unsafe Commits Suggests Improvements
Fixed Rules Adaptive Analysis
Instead of replacing each other, both approaches complement one another to create a stronger review process.
Step 5: Fixing the Security Issues
Once the warnings were identified, the script was updated by removing:
The hardcoded key
The debug statement
The corrected script became a simple placeholder notification script without exposing sensitive information.
After staging the changes, the commit was attempted again.
This time:
✅ The Git pre-commit hook passed.
✅ The AI review reported no issues.
This demonstrated the importance of responding to automated feedback before moving forward.
Step 6: Creating the Pull Request
The final task involved:
Pushing the feature branch
Creating a Pull Request against the personal fork
Using the AI-generated PR description as a starting point
Reviewing and editing the AI draft before submission
One important lesson became clear:
AI can assist developers, but humans remain responsible for validating and approving every change before it becomes part of the codebase.
Understanding the Agentic AI Workflow
This assignment introduced a simple but powerful Agentic AI Loop:
- Gather
Collect repository information using Git commands such as:
git status
git diff
- Analyze
Run:
Git Pre-Commit Hook
AI /pr-ready review
- Human Action
Developers review findings, fix issues, and improve the code.
- Verify
Run the automated checks again to confirm everything passes successfully before committing.
This workflow combines:
Automation
AI reasoning
Human judgment
to build more secure and reliable software.
Key Learnings
Built a custom Git pre-commit hook to detect secrets and prevent unsafe commits.
Learned how rule-based automation differs from AI-powered contextual code reviews.
Gained practical experience with Git feature branching, staging, committing, and Pull Request workflows.
Understood how Agentic AI enhances developer productivity by reviewing code intelligently while keeping humans in control.
Strengthened my understanding of DevSecOps by integrating security checks into the development workflow before code reaches the repository.
Conclusion
This assignment reinforced an important principle of modern software engineering:
Security should begin before the first commit—not after deployment.
Git hooks provide fast, automated protection against common mistakes, while AI-powered reviews offer contextual insights that traditional tools cannot provide alone. Together, they help developers deliver cleaner, safer, and higher-quality code.
As AI continues to become an integral part of software development, combining automation, intelligent analysis, and human decision-making will be key to building reliable and secure applications.
This post is part of the DevOps Micro Internship (DMI) with Agentic AI — Cohort 3 — by Pravin Mishra.
My graded progress is public: https://dmi.pravinmishra.com/s/DMI-C3-CharanTeja.html
Start your DevOps journey: https://dmi.pravinmishra.com/?utm_source=student&utm_medium=ps-blog&utm_campaign=cohort3
Top comments (0)