18

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 1

23
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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot! I looked at the documentation, but it was not clear to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.