In a python script, I try to checkout a tag after cloning a git repository. I use GitPython 0.3.2.
#!/usr/bin/env python
import git
g = git.Git()
g.clone("user@host:repos")
g = git.Git(repos)
g.execute(["git", "checkout", "tag_name"])
With this code I have an error:
g.execute(["git", "checkout", "tag_name"])
File "/usr/lib/python2.6/site-packages/git/cmd.py", line 377, in execute
raise GitCommandError(command, status, stderr_value)
GitCommandError: 'git checkout tag_name' returned exit status 1: error: pathspec 'tag_name' did not match any file(s) known to git.
If I replace the tag name with a branch name, I have no problem. I didn't find informations in GitPython documentation. And if I try to checkout the same tag in a shell, I have non problem.
Do you know how can I checkout a git tag in python ?
"tag_name"
and that is why the error happens. Regardless,git checkout <tag>
is the correct format, but you should also know that you shouldgit fetch
first, andgit pull origin refs/tags/<tag>
after. – Nathanielnathanil