0

i need an explanation or example python code to check does an branch exist. My repo is stored in an GitLab enviorement. I addded an GitLabVariable as an substitute of the Branchname.

branches = git.Git().branch("--all").split()
if os.environ.get('GitLabVariable') in branches:
torek
  • 448,244
  • 59
  • 642
  • 775
  • If you're looking to see if your branch exists remotely in Gitlab then you should consider using the [Gitlab API](https://python-gitlab.readthedocs.io/en/stable/gl_objects/branches.html?highlight=branch#examples) for that. If you're looking for branches locally in git then the [GitPython API](https://gitpython.readthedocs.io/en/stable/reference.html#git.repo.base.Repo.branches) is what you want. – alfinkel24 Aug 19 '21 at 16:50
  • https://stackoverflow.com/q/5167957/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+check+branch+exist – phd Aug 19 '21 at 16:51

0 Answers0