How to get the current checked out Git branch name through pygit2? December 30, 2023 by Tarik To get the conventional “shorthand” name: from pygit2 import Repository Repository('.').head.shorthand # 'master'