LoginSignup
0
0

More than 3 years have passed since last update.

ローカルでmasterブランチへのgit pushを禁ずる方法

Last updated at Posted at 2021-04-03

タイトルは嘘。

リモートへのgit pushを禁ずるために、ローカルでmasterブランチにgit commitができないようにした。
以下を、gitレポジトリ内に配置すればよい。

.git/hooks/pre-commit

branch=`git symbolic-ref HEAD`
if test "$branch" = "refs/heads/master" || test "$branch" = "refs/heads/main"; then
    echo "Direct commits to the master branch are not allowed."
    exit 1
fi

executableにする。


$ chmod +x .git/hooks/pre-commit      

すると、以下のようなエラーが出るようになった。

$ git commit -m 'test' --allow-empty    

Direct commits to the master branch are not allowed.

よし。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0