chore: add pre-commit hook to block direct pushes to main

Open Beginner friendly
#2 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
bash, git, yaml

Research direction

Start with the proposed .pre-commit-config.yaml in the repository root and the README setup section. Install pre-commit, run the hook on a feature branch and on main, and verify that direct pushes to main are blocked while the setup instructions are complete and accurate.

Written by the indexing model from the issue text.

Description

Problem

AI-assisted sessions occasionally push commits directly to main instead of creating a feature branch first. This bypasses code review and can introduce unreviewed changes to production pipelines.

Proposed fix

Add a pre-commit hook that blocks direct pushes to main.

.pre-commit-config.yaml in repo root:

repos:
  - repo: local
    hooks:
      - id: no-direct-main-push
        name: Block direct push to main
        entry: bash -c 'branch=$(git rev-parse --abbrev-ref HEAD); if [ "$branch" = "main" ]; then echo "ERROR: Direct push to main is blocked. Create a feature branch and open a PR."; exit 1; fi'
        language: system
        stages: [pre-push]

One-time setup per clone:

pip install pre-commit
pre-commit install --hook-type pre-push

This should also be documented in the repo README setup section.

Notes

  • pre-commit is already a standard tool in data engineering repos
  • The hook is bypassable with --no-verify (intentional escape hatch for genuine emergencies)
  • Branch protection rules would be the stronger fix but require a paid GitHub plan
Dominant language
HTML
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataStrategist/notes2kg

All issues in DataStrategist/notes2kg

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.