Skip to content

Instantly share code, notes, and snippets.

@Brimizer
Forked from igniteflow/git_python_current_branch.py
Last active November 8, 2022 13:33
Show Gist options
  • Save Brimizer/8fd44f5e84321b44080e to your computer and use it in GitHub Desktop.
Save Brimizer/8fd44f5e84321b44080e to your computer and use it in GitHub Desktop.
GitPython get current active branch
"""
Depends on GitPython
pip install GitPython
"""
from git import Repo
def get_current_branch_name(repo_path)
"""
Gets the name of the active Git branch as a string.
"""
repo = Repo('/path/to/your/repo')
branch = repo.active_branch
return branch.name
def
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment