Skip to content
\n

Is it possible to perform something like a git checkout tags/<my_tag> where I just switch to the current tag, but am able to switch also back to the current / latest commit on the repository?

","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"

That's quite alright, the issue was tagged accordingly. Thanks.

\n

That's a great finding! I did do some searching to come up with the following.

\n\n

I hope this answers the question - GitPython is a lot of 'low-level' plumbing, which makes some common operations unintuitive. These are best left to the git porcelain, provided by the git command-line interface.

\n

Even though I am closing the issue, please feel free to keep posting follow-ups.

","upvoteCount":1,"url":"https://github.com/gitpython-developers/GitPython/discussions/1157#discussioncomment-408811"}}}

Clone repository and “checkout” to "tags/<my_tag>" #1157

Answered by Byron
conFusl asked this question in Q&A
Discussion options

You must be logged in to vote

That's quite alright, the issue was tagged accordingly. Thanks.

That's a great finding! I did do some searching to come up with the following.

  • detach the HEAD to point to the tag: repo.head.set_reference(repo.tags[tag].commit
  • reset the working tree to the current commit, but… it seems wonky to do it like this especially since there is repo.git.checkout(tag) which does exactly what you want.

I hope this answers the question - GitPython is a lot of 'low-level' plumbing, which makes some common operations unintuitive. These are best left to the git porcelain, provided by the git command-line interface.

Even though I am closing the issue, please feel free to keep posting follow-ups.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Byron
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1026 on February 26, 2021 11:18.