Created
August 4, 2020 08:56
-
-
Save membrive/724ff26408127b3bace74ed08814843e to your computer and use it in GitHub Desktop.
Get the name of the current git branch using git binary and no other Python libraries
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
#!/usr/bin/env python3 | |
from subprocess import run, PIPE | |
branch_proc = run(['git', 'branch', '--show-current'], | |
stdout=PIPE, | |
universal_newlines=True, | |
cwd='.') # set CWD to the branch directory | |
if branch_proc.returncode == 0: | |
branch = branch_proc.stdout.strip('\n') | |
print(branch) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment