LoginSignup
9
2

More than 5 years have passed since last update.

特定のブランチでだけリモート名を省略した git push コマンドを禁止する

Posted at

状況

リモート名とブランチ名を省略した git push コマンドは、(git config の push.default 設定によるが)適切なリモートとブランチを補ってプッシュを実行する。たとえば upstream が origin/foo ブランチに設定された foo ブランチで git push を実行すると origin/foo にプッシュする。

この挙動を特定のブランチでだけ禁止したい。具体的には、誤操作を防ぐために master ブランチでだけ git push を禁止して、明示的な git push origin master だけを許可したい。

解法

リモート名を省略した場合に補われるリモートを存在しない名前にすればよい。 branch.<name>.pushRemote を以下のように設定する。

git config branch.master.pushRemote 'dont-push-master!!!'

git push すると存在しないリモートにプッシュしようとして期待通りエラーになる。

スクリーンショット 2019-04-24 17.03.45.png

9
2
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
9
2