git push 使用 python

Sam*_*Sam 5 git git-push python-3.x gitpython

我有本地 git 存储库。我正在使用 python 使用 gitpython 库提交本地存储库。我想将提交推送到 github。我如何使用 gitpython 或任何其他库来做到这一点。我在网上看了,但没有可用的解决方案。谁能帮我这个。提前致谢

Sam*_*Sam 8

from git import Repo,remote

rw_dir = 'path/to/your/local/repo'
repo = Repo(rw_dir)

'''Enter code to commit the repository here.
After commit run the following code to push the commit to remote repo.
I am pushing to master branch here'''

origin = repo.remote(name='origin')
origin.push()
Run Code Online (Sandbox Code Playgroud)

  • 虽然此代码片段可能会解决问题,但 [包括解释](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而那些人可能不知道您提出代码建议的原因。[来自评论](https://stackoverflow.com/review/low-quality-posts/15052961) (7认同)