pythonスクリプトでgitコマンドを実行する

Windows環境でプロンプト等を開いて毎回git push、pullコマンドをうつのが面倒だったので、それらのスクリプトをpythonで書いてみました。
以下のプログラムはgitで管理しているディレクトリの一番上で実行します。

実行環境

  • python 3.6.5
  • Git for Windows

Pull コマンド

#!/usr/bin/env python3
import os
# Push
os.system('git pull')
view raw git_pull.py hosted with ❤ by GitHub

Push コマンド

以下のプログラムを実行すると、その時点での時間"年:月:日-時:分:秒"でコミットして、Pushします。

#!/usr/bin/env python3
import os
from datetime import datetime
# Commit comment
now = datetime.now()
comment = datetime.now().strftime("%Y/%m/%d-%H:%M:%S")
# Push
os.system('git add .')
os.system('git commit -m {}'.format(comment))
os.system('git push')
view raw git_push.py hosted with ❤ by GitHub

コメント