Skip to content

Instantly share code, notes, and snippets.

@zfenj
Forked from Brimizer/git_repo_info.py
Created March 3, 2019 19:35
Show Gist options
  • Save zfenj/c9a2f79c6424dcdd503839dbe0f6cf08 to your computer and use it in GitHub Desktop.
Save zfenj/c9a2f79c6424dcdd503839dbe0f6cf08 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