0

I'm writing a Python script that executes a few git commands to the shell. I have everything working exactly as I want for the most part. My only issue is it seems subprocess is adding extra characters to a string I want to get. This is some example code:

import subprocess

def main():
    branchName = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE).stdout.strip()
    print(branchName)

Output:

b'BranchName'

For whatever reason it adds a 'b' and single quotes to the shell output for that command. If I run the command straight from bash I get:

BranchName

Is there anyway to strip these extra characters from the output from subprocess without any messy string manipulation?

Floyd
  • 55
  • 6

0 Answers0