AcademyTimeline Architect: Mastering the Time MachineProtocol 8: Code Ethics

Lesson 2: The Craftsman (Commit Messages & Git Hooks)

A great DevOps engineer doesn't just write code — they write craft-quality commits. Your commit history is the story of your project. Make it readable, searchable, and professional.

The Art of Commit Messages

The Conventional Commits Standard

Many teams use a structured format:

<type>(<scope>): <description>

[optional body]

[optional footer]

Types:

| Type | When to Use | Example | |------|-------------|---------| | feat | New feature | feat: add dark mode toggle | | fix | Bug fix | fix: resolve login redirect loop | | docs | Documentation | docs: update API reference | | style | Formatting (no logic change) | style: fix indentation in config | | refactor | Code restructuring | refactor: extract auth middleware | | test | Adding tests | test: add unit tests for payment | | chore | Maintenance | chore: update dependencies | | ci | CI/CD changes | ci: add staging deploy step |

Good vs. Bad Messages

# ❌ Bad
git commit -m "fix"
git commit -m "update"
git commit -m "WIP"
git commit -m "asdfgh"

# ✅ Good
git commit -m "fix: prevent null pointer in user serializer"
git commit -m "feat: add rate limiting to API endpoints"
git commit -m "docs: add deployment guide for AWS"

Git Aliases — Custom Shortcuts

Create shortcuts for commands you use constantly:

git config --global alias.st 'status'
git config --global alias.co 'checkout'
git config --global alias.br 'branch'
git config --global alias.ci 'commit'
git config --global alias.lg 'log --oneline --graph --all --decorate'
git config --global alias.last 'log -1 HEAD'
git config --global alias.unstage 'restore --staged'

Now you can type git lg instead of the full log command!

Git Hooks — Automated Quality Gates

Git hooks are scripts that run automatically at key moments:

| Hook | When It Runs | Common Use | |------|-------------|------------| | pre-commit | Before each commit | Run linters, format code | | commit-msg | After writing message | Enforce message format | | pre-push | Before pushing | Run tests | | post-merge | After a merge | Install dependencies |

Example pre-commit hook (.git/hooks/pre-commit):

#!/bin/bash
echo "Running linter..."
npm run lint
if [ $? -ne 0 ]; then
  echo "❌ Lint failed. Fix errors before committing."
  exit 1
fi
echo "✅ Lint passed!"

The Complete Git Workflow

# 1. Start your day
git pull --rebase origin main

# 2. Create a feature branch
git checkout -b feat/user-settings

# 3. Work in small, focused commits
git add .
git commit -m "feat: add settings page layout"
git commit -m "feat: add theme preference toggle"
git commit -m "test: add settings page unit tests"

# 4. Push and create PR
git push -u origin feat/user-settings

# 5. After PR approval
git checkout main
git pull
git branch -d feat/user-settings
booting...

Mission Objective

Become a commit craftsman:

  1. Write well: Create a commit with git commit -m 'feat: add user profile page with avatar upload'.
  2. Create a shortcut: Set up an alias with git config alias.lg 'log --oneline --graph --all'.
  3. Use it: Run git lg to see your beautiful history.

🎉 Congratulations!

You've completed the Git & Version Control course! You now understand the full Git workflow — from your first commit to advanced forensics. These skills are the foundation of every DevOps pipeline.

Next Steps:

  • Practice daily: Use Git for every project, even personal ones.
  • Explore GitHub Actions for CI/CD automation.
  • Set up Git hooks with tools like Husky for JavaScript projects.
  • Learn Docker — the next step in your DevOps journey!

Mission Control

Write a well-structured commit message

Expected Command

git commit -m 'feat: add user profile page with avatar upload'

Create a useful Git alias

Use your new alias