def branch_exists(branch):
 cmd = ['git', 'rev-parse', '--symbolic', '--verify', branch]
 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
 (out, _) = p.communicate()
 if p.returncode:
  return False
 return (out.rstrip() == branch)

def branch_exists ( branch ) : cmd = [ 'git' , 'rev-parse' , '--symbolic' , '--verify' , branch ] p = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) ( out , _ ) = p . communicate ( ) if p . returncode : return False return ( out . rstrip ( ) == branch )
make sure that the given ref name really exists .