How can I run the below command in Python 3.8 and get the output?
Command:
git remote show [URL for remote Github repo] | sed -n '/HEAD branch/s/.*: //p'
Command purpose:
To get the default branch from remote Github repo also trying to run this outside git directory
Below are the commands I have tried till now, but it gives error: "fatal: not a git repository (or any of the parent directories): .git":
import os
p = os.system("git remote show https://github.com/docker/compose | grep 'HEAD branch' | cut -d' ' -f5")
import subprocess
subprocess.run(["git", "remote", "show", "https://github.com/docker/compose", "|", "grep", "'HEAD branch'", "|", "cut", "-d' '", "-f5" ])
I need the command to execute even outside the Git directory, please help me