Using Gitpython, How Can I Checkout a Certain Git Commit Id?

Using Gitpython, How Can I Checkout a Certain Git Commit Id?

Checking out a branch works well, but I also need to check out a certain commit ID in a given Git repository.

I mean the equivalent of

git clone --no-checkout my-repo-url my-target-path
cd my-target-path
git checkout my-commit-id

How can I do this with gitpython?

1 Answer

repo = git.Repo.clone_from(repo_url, repo_path, no_checkout=True)
repo.git.checkout(commit_id)

You can find more details in the documentation.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.