0

i have an git repo in gitlab. And i tried to switch the branch with the following instructions. And i got the following error OSError: Reference at 'refs/heads/past_branch' does already exist, pointing to '.......', requested was '......' Where is my issue?

repo = Repo(self.rorepo.working_tree_dir)
# Reset our working tree 10 commits into the past
past_branch = repo.create_head('past_branch', 'HEAD~10')
self.assertRaises(git.GitCommandError, repo.heads.master.checkout)
repo.heads.past_branch.checkout()
phd
  • 82,685
  • 13
  • 120
  • 165
  • https://stackoverflow.com/search?q=%5Bgitpython%5D+switch+branch – phd Aug 12 '21 at 12:14
  • `repo.create_head()` creates **a new** branch. It's already created so you cannot create it for the second time. To switch to that branch use `git.checkout()`. Next time please read docs and use search before asking questions. – phd Aug 12 '21 at 12:15

0 Answers0