1

i have an git repo in gitlab. I tried to checkout the master branch with the following lines.

repo = git.Repo(os.path.dirname(__file__), search_parent_directories=True) repo.git.checkout("master") ref_repo_root = os.path.join(WORKING_DIRECTORY, 'ref_decoders') 

But i got the following error.

E git.exc.GitCommandError: Cmd('git') failed due to: exit code(1) E cmdline: git checkout master E stderr: 'error: pathspec 'master' did not match any file(s) known to git.' 

What i know repo.git.checkout("HEAD~1") works fine. Where is my issue?

6
  • 1
    Is there in fact a branch named master? That isn't exactly guaranteed any more - for political reasons, some hosting services arrange things (or give you setup steps to arrange things) to name the primary branch something else. Commented Aug 13, 2021 at 6:41
  • To be clear, are you using this package to interface with git? Or something else? Commented Aug 13, 2021 at 6:42
  • Hi Karl, i use the following python-git package. Commented Aug 13, 2021 at 7:02
  • What branches does the repository have? Run git branch -a. Commented Aug 13, 2021 at 7:39
  • This repository has an master an other branches. I tried to checkout all this branches. But the issue is the same. And it's works for Head~1 Commented Aug 13, 2021 at 7:46

1 Answer 1

2

The default branch in gitlab since v14.0 is main and not master. Read here for more info: https://about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/

Sign up to request clarification or add additional context in comments.

4 Comments

Hi, thanks for this hint. But i got the same issue. E git.exc.GitCommandError: Cmd('git') failed due to: exit code(1) E cmdline: git checkout main E stderr: 'error: pathspec 'main' did not match any file(s) known to git.'
Does the master/main branch exist at all?
Hi Gabip, the master does exist.
You mentioned that repo.git.checkout("HEAD~1") works. What branch does git think you're on currently (what does it say in git status)?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.