目次
毎回Gitコマンドを手動で実行するのが面倒でした。cronで自動化したので、備忘録として残します。
設定手順
以下のコマンドでcrontabを編集モードで開きます。
crontab -e
エディタが開いたら、次のような行を追加します。
0 0 * * * cd /path/to/your/git/repository && git add . && git commit -m "Automatic commit" && git push
各部分の意味は以下の通りです。
| 部分 | 説明 |
|---|---|
0 0 * * * |
実行スケジュール(分 時 日 月 曜日)。この例は毎日午前0時 |
cd /path/to/... |
Gitリポジトリのディレクトリに移動 |
git add . |
変更されたファイルをステージング |
git commit -m "..." |
指定メッセージでコミット |
git push |
リモートリポジトリにプッシュ |
停止と削除
一時停止したい場合は、行の先頭に#を追加してコメントアウトします。完全に削除したい場合は、該当行を削除してください。
#0 0 * * * cd /path/to/your/git/repository && git add . && git commit -m "Automatic commit" && git push
