How to git fetch using gitpython?

devops picture devops · Oct 5, 2016 · Viewed 8.6k times · Source

I am looking for a equivalent way to fetch in gitpython

git fetch --quiet --all

How can I perform git fetch in python?

Answer

zeantsoi picture zeantsoi · Oct 5, 2016

The fetch method is equivalent to issuing git fetch. Accordingly, you can fetch all your remotes by iterating and fetching each individually:

repo = git.Repo('name_of_repo')
for remote in repo.remotes:
    remote.fetch()