Skip to content

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

@conFusl

Description

@conFusl

More a general Q/A than an issue, but I'm struggling with this topic.

I clone a repository using Repo.clone_from(). Afterwards, I simply want to switch to a specified tag within the repository, similar to git checkout tags/<my_tag>.

I found the following solution, but it resets HEAD of my master branch, which is not what I want:

        logging.info("Cloning repo... " + name)
        repo = Repo.clone_from(url, path)
        repo.head.reference = repo.tags[tag].commit

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions