Have you considered using GitPython? It's designed to handle all this nonsense for you.

import git  # pip install gitpython


g = git.cmd.Git(git_dir)
g.pull()

To install the module use pip install GitPython

Project can be found here, GitPython

Answer from jleahy on Stack Overflow
🌐
Readthedocs
gitpython.readthedocs.io › en › stable › tutorial.html
GitPython Tutorial — GitPython 3.1.46 documentation
# Create a new submodule and check it out on the spot, setup to track master # branch of `bare_repo`. As our GitPython repository has submodules already that # point to GitHub, make sure we don't interact with them.
🌐
GitHub
gist.github.com › romach › 27a4c3dee97d9bf2213c6c3b379fd7e4
Git pull from Python · GitHub
Git pull from Python. GitHub Gist: instantly share code, notes, and snippets.
🌐
PyPI
pypi.org › project › git-pull-request
git-pull-request · PyPI
Although it might not be up to date with the latest code on GitHub Fedora 28+ users can also download straight via package manager DNF: ... Create a pull-request for your current branch to the remote matching branch, or master by default. If you add more commits to your branch later, or need to rebase your branch to edit commits, you’ll just need to run git pull-request to update your pull-request.
      » pip install git-pull-request
    
Published   Jan 04, 2022
Version   6.0.2
🌐
GitHub
github.com › BenjaFriend › AutoPull
GitHub - BenjaFriend/AutoPull: A simple python script to automatically pull any repos in the containing folder. Specifically useful for those using Git for school assignments and need to grade.
April 12, 2022 - A simple python script to automatically pull any repos in the containing folder. Specifically useful for those using Git for school assignments and need to grade. - GitHub - BenjaFriend/AutoPull: A simple python script to automatically pull ...
Author   BenjaFriend
🌐
Medium
zchelseal.medium.com › automate-your-git-workflow-with-gitpython-3320e833c4e2
Automate Your Git Workflow with GitPython | by Chelsea Liu | Medium
April 13, 2021 - repo.git.push("--set-upstream", origin, repo.head.ref) Construct a url that leads us to a PR-creation page (this method is hacky but safe for as long as GitHub keeps this convention): "https://{}/pull/new/{}".format(link_to_your_github_repo, your_branch_name)
🌐
GitHub
github.com › liferay › git-tools › blob › master › git-pull-request › git-pull-request.py
git-tools/git-pull-request/git-pull-request.py at master · liferay/git-tools
· Usage: · gitpr [<options>] <command> [<args>] · Options: · -h, --help · Display this message. · -r <repo>, --repo <repo> Use this github repo instead of the 'remote origin' or 'github.repo' git config setting.
Author   liferay
Find elsewhere
🌐
GitHub
github.com › msiemens › PyGitUp
GitHub - msiemens/PyGitUp: A nicer `git pull`
The original git-up has been written by aanand: aanand/git-up/. Switch to packaging instead of pkg_resources. Closes #139. Fix top-level directory detection on MinGW. Update dependencies and switch to the uv package manager. Improve logging when updating large repositories. Thanks @bdmartin for Pull Request #132. ... Add support for Python 3.11.
Starred by 537 users
Forked by 45 users
Languages   Python 100.0% | Python 100.0%
🌐
Python Developer's Guide
devguide.python.org › getting-started › pull-request-lifecycle
Lifecycle of a pull request
Finally go on https://github.com/<your-username>/cpython: you will see a box with the branch you just pushed and a green button that allows you to create a pull request against the official CPython repository.
🌐
Python Snacks
pythonsnacks.com › p › using-git-push-and-git-pull-for-your-python-code
[DELETE] Using Git Push and Git Pull for your Python Code
April 14, 2025 - Great, now that your team can see your changes they need a way to bring it down from GitHub. They can do this by running the git pull command: ... Now, your team can see all of the changes that you made to your button. Similarly, if your co-worker pushed up a change that is a separate from your work on the button, you can run the git pull command to pull their changes to your local machine. Want even more Python-related content that’s useful?
🌐
GeeksforGeeks
geeksforgeeks.org › python › automating-some-git-commands-with-python
Automating some git commands with Python - GeeksforGeeks
April 28, 2025 - import git repo = git.Repo("/path/to/local/repo") origin = repo.remote(name='origin') origin.pull() Output: Pulled Changes from the origin · Verify: New file hacktoberfest_tree_cert.pdf got pulled from the origin and got saved to the local machine. Comment · Article Tags: Article Tags: Technical Scripter · Python · GitHub ·
🌐
Python Developer's Guide
devguide.python.org › gitbootcamp
Git bootcamp and cheat sheet
You should have been redirected · If not, click here to continue
🌐
AskPython
askpython.com › home › how to use gitpython to pull remote repository?
How To Use GitPython To Pull Remote Repository? - AskPython
June 30, 2023 - repo.git.pull() is executing the “git pull” command on the local repository using the repo object. Your local repository will now have all the updates from the git repository.
🌐
GitHub
github.com › gitpython-developers › GitPython
GitHub - gitpython-developers/GitPython: GitPython is a python library used to interact with Git repositories. · GitHub
Style and formatting checks, and running tests on all the different supported Python versions, will be performed: Upon submitting a pull request. On each push, if you have a fork with GitHub Actions enabled.
Starred by 5.1K users
Forked by 968 users
Languages   Python
🌐
GitHub
github.com › python › cpython › pulls
Pull requests · python/cpython
python / cpython Public · There was an error while loading. Please reload this page. Notifications · You must be signed in to change notification settings · Fork 34.4k · Star 72.2k · New pull request New · 2,151 Open 67,688 Closed · 2,151 Open 67,688 Closed ·
Author   python
🌐
PDX
web.pdx.edu › ~gjay › teaching › mth271_2020 › html › 03_Working_with_git.html
Git Repo class in python
In particular, executing this notebook will pull the updated data from GitHub and place it in a location you specify (below). If you want to know more about git, there are many resources online, such as the Git Handbook. The most common way to fetch materials from a remote repository is using git's command line tools, but for our purposes, the python ...
Top answer
1 of 3
9

GitPython is only a wrapper around Git. I assume you are wanting to create a pull request in a Git hosting service (Github/Gitlab/etc.).

You can't create a pull request using the standard git command line. git request-pull, for example, only Generates a summary of pending changes. It doesn't create a pull request in GitHub.

If you want to create a pull request in GitHub, you can use the PyGithub library.

Or make a simple HTTP request to the Github API with the requests library:

import json
import requests

def create_pull_request(project_name, repo_name, title, description, head_branch, base_branch, git_token):
    """Creates the pull request for the head_branch against the base_branch"""
    git_pulls_api = "https://github.com/api/v3/repos/{0}/{1}/pulls".format(
        project_name,
        repo_name)
    headers = {
        "Authorization": "token {0}".format(git_token),
        "Content-Type": "application/json"}

    payload = {
        "title": title,
        "body": description,
        "head": head_branch,
        "base": base_branch,
    }

    r = requests.post(
        git_pulls_api,
        headers=headers,
        data=json.dumps(payload))

    if not r.ok:
        print("Request Failed: {0}".format(r.text))

create_pull_request(
    "<your_project>", # project_name
    "<your_repo>", # repo_name
    "My pull request title", # title
    "My pull request description", # description
    "banana-refresh", # head_branch
    "banana-integration", # base_branch
    "<your_git_token>", # git_token
)

This uses the GitHub OAuth2 Token Auth and the GitHub pull request API endpoint to make a pull request of the branch banana-refresh against banana-integration.

2 of 3
3

It appears as though pull requests have not been wrapped by this library.

You can call the git command line directly as per the documentation.

repo.git.pull_request(...)

🌐
Python GUIs
pythonguis.com › tutorials › getting started with git and github in your python projects
Git and GitHub for Python Projects: A Beginner's Guide to Version Control
March 20, 2023 - This makes a new commit on your remote repository. This remote commit won't appear in your local commit history. To download it and update your local main branch, use the git pull command: