Skip to content

Instantly share code, notes, and snippets.

@PaperNick
Created September 28, 2019 19:41
Show Gist options
  • Select an option

  • Save PaperNick/08ba06b2e9e1f7d94150594d88689fff to your computer and use it in GitHub Desktop.

Select an option

Save PaperNick/08ba06b2e9e1f7d94150594d88689fff to your computer and use it in GitHub Desktop.

Revisions

  1. PaperNick created this gist Sep 28, 2019.
    18 changes: 18 additions & 0 deletions disallow-commits-in-branches.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    ## How to install

    ```bash
    #!/bin/bash

    current_branch="$(git symbolic-ref --short HEAD)"

    FORBIDDEN_BRANCHES=(master develop)
    for forbidden_branch in "${FORBIDDEN_BRANCHES[@]}"; do
    if [ "$current_branch" == "$forbidden_branch" ]; then
    echo 'You are not allowed to commit in this branch.'
    exit 1
    fi
    done
    ```

    1. Copy the content of this hook in `/your/project/.git/hooks/pre-commit`
    2. Make the pre-commit hook executable `chmod +x /your/project/.git/hooks/pre-commit`