问题
I'm new to gitpython and haven't been able to find a reference to this anywhere. What I'm looking to do is something like:
If remote branch name exists:
do something
else:
do something else
Any suggestions?
回答1:
This may not work, but give it a shot let me know how it goes:
does_exist = True
try:
repo.git.checkout('branch_name')
except repo.exc.GitCommandError:
does_exist = False
print(does_exist)
This may also work but give it a try:
repo.git.rev_parse('--verify', 'branch_name')
回答2:
Thanks Muadh! I was able to get this to work:
try:
repo.git.checkout( 'origin/' + branch_name, b=branch_name )
except:
repo.git.checkout( 'origin/master', b=branch_name )
来源:https://stackoverflow.com/questions/50707781/gitpython-how-to-check-if-a-remote-branch-exists