{"id":351,"library":"gitpython","title":"GitPython","description":"GitPython is a Python library used to interact with Git repositories. The current version is 3.1.46, released on March 28, 2026. It follows a regular release cadence, with updates addressing bug fixes, feature enhancements, and security patches.","status":"active","version":"3.1.46","language":"python","source_language":"en","source_url":"https://github.com/gitpython-developers/GitPython","tags":["git","python","version control","library"],"install":[{"cmd":"pip install gitpython","lang":"bash","label":"Install GitPython"}],"dependencies":[{"reason":"Required for GitPython's functionality","package":"gitdb"},{"reason":"Required for GitPython's functionality","package":"smmap"}],"imports":[{"note":"Ensure 'git' is the correct package name; 'gitpython' is the package name, but the import uses 'git'.","symbol":"Repo","correct":"from git import Repo"}],"quickstart":{"code":"import os\nfrom git import Repo\n\n# Set the repository path\nrepo_path = os.environ.get('REPO_PATH', '/path/to/your/repo')\n\n# Initialize the repository\nrepo = Repo(repo_path)\n\n# Access the latest commit\ncommit = repo.head.commit\n\n# Print the commit message\nprint(f'Latest commit: {commit.message}')","lang":"python","description":"This script demonstrates how to initialize a Git repository and access the latest commit message using GitPython. Replace '/path/to/your/repo' with the actual path to your Git repository."},"warnings":[{"fix":"Upgrade your Python installation to version 3.7 or higher.","message":"GitPython requires Python 3.7 or higher. Attempting to use it with an older version will result in an ImportError.","severity":"breaking","affected_versions":"all"},{"fix":"Install the missing dependencies using pip: pip install gitdb smmap.","message":"Ensure that both 'gitdb' and 'smmap' are installed, as they are dependencies for GitPython. Missing these can lead to ImportError.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the 'git' command-line tool is installed and its executable is discoverable in the system's PATH. For example, on Debian/Ubuntu: `sudo apt-get update && sudo apt-get install git`. Alternatively, set the `GIT_PYTHON_GIT_EXECUTABLE` environment variable to the full path of the git executable.","message":"GitPython requires the 'git' command-line tool to be installed and accessible in the system's PATH, or its path explicitly configured. Missing 'git' will result in an ImportError.","severity":"breaking","affected_versions":"all"},{"fix":"Ensure the 'git' command-line tool is installed on your system and available in the system's PATH. For Alpine Linux, use `apk add git`. For Debian/Ubuntu, use `apt-get install git`. Alternatively, set the environment variable `GIT_PYTHON_GIT_EXECUTABLE` to the full path of the git executable.","message":"GitPython requires the 'git' command-line tool to be installed on the system and accessible in the system's PATH, or explicitly configured. Failure to do so will result in an ImportError: Bad git executable.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-12T13:13:56.737Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure GitPython is installed with `pip install GitPython` and then import `Repo` or other classes directly from the `git` package, or use `import git` if you intend to use the top-level namespace.","cause":"This error occurs because the `gitpython` library is installed, but Python attempts to import a module literally named 'git', which is the top-level package name for the GitPython library, instead of the library's entry point.","error":"ModuleNotFoundError: No module named 'git'"},{"fix":"Install Git (the command-line tool) on your system and ensure its executable is included in your system's PATH. Alternatively, set the `GIT_PYTHON_GIT_EXECUTABLE` environment variable to the full path of the git executable, or explicitly set it in your Python code using `git.refresh(path='/path/to/git')`.","cause":"GitPython requires the underlying Git command-line tool to be installed and accessible in the system's PATH. This error indicates that GitPython cannot locate the `git` executable.","error":"ImportError: Failed to initialize: Bad git executable. The git executable must be specified in one of the following ways:..."},{"fix":"Verify that the repository URL is correct and that the repository actually exists at that location. Pay attention to typos, case sensitivity, and network connectivity.","cause":"This error indicates that the remote Git repository specified in the clone URL does not exist or the URL is incorrect.","error":"git.exc.GitCommandError: 'git clone ...' returned exit status 128: remote: Repository not found"},{"fix":"Provide correct authentication credentials (e.g., embed them in the URL for HTTPS clones, use an SSH agent for SSH, or configure Git's credential helper). For HTTPS, if 2FA is enabled, use a personal access token instead of your password. For SSH, ensure your SSH keys are correctly set up and added to the remote server.","cause":"This error signifies that GitPython, when attempting to clone or interact with a remote repository, encountered an authentication failure. This is often due to incorrect credentials (username/password, personal access token, or SSH key issues) or insufficient permissions for the repository.","error":"git.exc.GitCommandError: 'git clone ...' returned exit status 128: fatal: Authentication failed for 'https://...' / fatal: could not read Username for 'https://...': No such device or address"},{"fix":"Rename any local file or directory named `git.py` or `git` that might be conflicting with the installed GitPython library. Ensure GitPython is properly installed and your Python environment's `sys.path` is correctly configured.","cause":"This error typically occurs when there is a naming conflict, such as a local file named `git.py` in the same directory as your script, which 'shadows' the actual installed `git` package from GitPython. It can also occur if GitPython was not correctly installed or if the Python environment is misconfigured.","error":"AttributeError: module 'git' has no attribute 'Repo'"}],"ecosystem":"pypi","meta_description":null,"install_score":0,"install_tag":"stale","quickstart_score":0,"quickstart_tag":"stale","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"stale","tag_description":"widespread failures or data too old to trust","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}