# force fail commit on master

Most of the time, you want to fail if you mistakenly commit to master. This is if you normally work with feature branch. This script can make git commit fail if the branch is master

add to `.git/hooks/pre-commit`

```
 current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
 if [ "$current_branch" == "master" ]
 then
   echo "Should not commit on master branch. Use 'git commit -n' to override"
   exit 1
 fi
```

or you can check out [pre-commit](https://github.com/pre-commit/pre-commit) a framework to manage your git commit scripts


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://til.yulrizka.com/git/force-fail-commit-on-master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
