nidHi
nidHi

Reputation: 833

Not able to clone repository through gitpython

I am trying to clone a gerrit project onto my local machine through gitpython which I installed through the following command.

pip install gitpython

I have a python script with the following code.

#git.py

import git
git.Git().clone("ssh://user@host_ip:port/proj1")

This is not giving me the expected result. It gives me the following error.

AttributeError: 'module' object has no attribute 'Git'

I can run just git clone ssh://user@host_ip:port/proj1, which works perfectly fine and gives me a cloned repository but not through the script.

Also, after installing gitpython, the first time I enter python command shell, import git does not give any error. But, if I do the the same after running the git.py script mentioned above, I get the same error AttributeError: 'module' object has no attribute 'Git'.

I don't know where I am going wrong and would like some guidance.

Upvotes: 1

Views: 1762

Answers (2)

natschz
natschz

Reputation: 1117

I guess that code you use was for a different git library. Take a look at their documentation, i guess something like this should do the trick:

import git
git.Repo.clone_from(url, path)

I didn't actually tested it but anyway I hope this helps!

Upvotes: 2

wRAR
wRAR

Reputation: 25559

As your file is called git.py, it is imported when import git is executed. You need to rename it.

Upvotes: 2

Related Questions