-
-
Save zfenj/c9a2f79c6424dcdd503839dbe0f6cf08 to your computer and use it in GitHub Desktop.
GitPython get current active branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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