Git Product home page Git Product logo

git-hooks-is-all-you-need's Introduction

Git Hooks Tutorial

My public talk about this project at Sberloga:
Git Hooks Is All You Need

1. Git Hooks 101

  1. Init git repo:
mkdir git_repo
cd git_repo

git init
  1. Git hooks are located in .git/hooks folder:
ls -lah .git/hooks
  1. Create executable (chmod +x) pre-commit hooks (path: .git/hooks/pre-commit):
  • bash hook with exit code 0
  • bash hook with exit code 1
  • python hook with exit code 0

Make commit after each step. You'll see different results.

2. Python pre-commit library

  1. Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Install and activate pre-commit library:
pip install pre-commit
pre-commit install
  1. Create pre-commit configuration file .pre-commit-config.yaml.
    Alternatively, you can use local configuration.

  2. Create main.py file.
    Make commit. Pre-commit library will reformat file according to PEP8.
    Remove unused import sys string to get ready-to-commit main.py file.

3. Remote repo

  1. Init empty "remote" repo:
git init --bare ../remote_repo.git
  1. Link local and "remote" repo:
git remote add origin ../remote_repo.git
  1. Create executable (chmod +x) pre-receive hook on "remote" (path: ../remote_repo.git/hooks/pre-receive).
    Make push and see the result.

Reference

Useful links:

  • git hooks intro: link
  • git hooks usage: link
  • pre-commit page: link

git-hooks-is-all-you-need's People

Contributors

dayyass avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.