by

How to check if a Git remote repository is available in python

This simple python code shows how to check if a given Git remote repository is available.

The code invokes the git command 'git ls-remote' on the remote URL path as subprocess with Popen and checks the exit code, using the communicate() method.

The command exit status is stored into the 'returncode' property.

A value not-equals to '0' means the command returned with errors.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/28845/How-to-check-if-a-Git-remote-repository-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
from subprocess import Popen, PIPE, STDOUT p = Popen(["git", "ls-remote", "git://remote_path"], stdout=PIPE) output = p.communicate()[0] if p.returncode != 0: print "Command failed ["+str(p.returncode)+"]"
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus