LoginSignup
5
5

More than 1 year has passed since last update.

Git | push の前に任意のプログラムを走らせてミスを減らす

Last updated at Posted at 2016-03-11

解決

git のエイリアスとして、push 前に走らせたいコマンドを登録しておく。

~/.gitconfig
[push]
  default = current
[alias]
  before-push = !bundle exec rubocop && bundle exec rake notes && echo 'sleep 10 seconds and you will push' && sleep 10

  gentle-push = !git before-push && git push

そして $ git gentle-push とコマンドすれば良い。

上は rubocop ( Ruby の文法チェッカ ) と、 notes ( アノテーションを見つけてくれるタスク ) を走らせている例。

結果

こんな感じ。

image

image

説明

  • 10秒スリープしているのは、何かエラーが起きた時に、Command+C で抜けられるようにするため。自動では止まらないので注意。
  • 必要な部分は適時書き換えて欲しい。たとえば、push を push -f にしたり。

組み合わせ

before-push に 現在のブランチを1コマンドで「最新のマスター」にリベースするエイリアス も入れておくと素敵だ。

~/.gitconfig
[push]
  default = current

[alias]
new-world = !git checkout master && git pull origin master && git checkout - && git rebase master

before-push = !git new-world && bundle exec rubocop && bundle exec rake notes && echo 'sleep 5 seconds and you will push' && sleep 5

問題

push 前に走らせるべきものを、忘れてしまうことが多い。 間違いは手元で分かったほうが良い。

環境

  • git version 2.3.8 (Apple Git-58)
  • Mac OSX Yosemite

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

メンター受付

5
5
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
5
5