1

I want to clone git repository with parameters (--recursive, -b <branch>) but I get the following error.

Traceback (most recent call last):
 File "./git-clone.py", line 15, in <module>
 r = git.Repo.clone(repo_dir, b=branch, recursive=git_url)
TypeError: unbound method clone() must be called with Repo instance as first argument (got str instance instead)

Here is my code:

#!/usr/bin/env python
import git
import os
import shutil
git_url = "<url>..."
repo_dir = "/home_local/user/git-repository"
branch = "branch"
if os.path.exists(repo_dir):
 shutil.rmtree(repo_dir)
r = git.Repo.clone(repo_dir, b=branch, recursive=git_url)

If I replace git.Repo.clone with git.Repo.clone_from its working fine but this command not accept my parameters.

asked Aug 5, 2015 at 9:18

1 Answer 1

4

try:

r = git.Repo.clone_from(git_url, repo_dir, branch=branch, recursive=True)

The first argument, is where you cloning from (the remote repository). The second argument is where you want to store the clone. All other arguments are passed on to git-clone command. eg --branch="branch" and --recursive. You should probably stick to the long argument names rather than the abbreviations. Since the recursive flag is either present or not, it's values can only be True or False.

answered Aug 5, 2015 at 9:37
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.