8
5

More than 5 years have passed since last update.

PythonでリモートリポジトリにCommit&Pushする最も簡単な方法

Last updated at Posted at 2019-09-11

Pythonの良さは色々なところで耳にしますが、Gitの操作も非常に容易に出来ます。

下記は、Pythonを使ったGit操作の例です。

git.py
import os
import git

#Pushしたいリポジトリに移動
os.chdir(r'C:\repo')
repo = git.Repo()

#最新を取り込むため一旦Pull
o = repo.remotes.origin
o.pull()

#Commit(サブディレクトリ含めて全て)
repo.git.commit('.','-m','\"Commit Log\"')

#Push
origin = repo.remote(name='origin')
origin.push()

サンプルの注意事項:
・既にGitの設定がローカルPCで出来ていて、Cloneされているものとします。
・プラグインをインストール済みの環境です。インストールしていない方は、pip install gitpythonを実行しましょう。

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