Skip to content Skip to sidebar Skip to footer

Python Script To Git Clone Without Entering A Password At The Prompt

I am trying to clone a project from the private git repository git clone gitolite@10.10.10.55:/Intel/BareRepos/lteue.git using the Python script. The problem with my script is I ne

Solution 1:

The best thing to do it use public/private keys. However, I don't know gitolite at all. (You may want to add that into the tags.)

Note, I would not recommend doing the following, unless you know no one unauthorized will see your script. This is bad security practice, etc.

If you really want this to be in Python, I would use subprocess.Popen.

from subprocess import Popen, PIPEpassword='rather_secret_string'

proc = Popen(['git', 'clone', 'gitolite@10.10.10.55:/Intel/BareRepos/lteue.git'], stdin=PIPE)

proc.communicate(password)

Solution 2:

I would use subprocess to do this.

So you use Popen() to create a process and then you can communicate with it. You do need to use PIPE to get your password to the input.

from subprocess import Popen, PIPEprocess= Popen(["git", "clone", "gitolite@10.10.10.55:/Intel/BareRepos/lteue.git"], stdin=PIPE)

process.communicate('password that I send')

Something like this will probably work.

You can also use Pexpect but I am not familiar with that library.

Solution 3:

I don't know why the above answers didn't work for me. But I come up with the new solution which will work for sure and it is very simple.

Here is my complete code:

import os
import sys
import shutil

path        =   "/path/to/store/your/cloned/project" 
clone       =   "git clone gitolite@10.10.10.55:/Intel/BareRepos/lteue.git"os.system("sshpass -p your_password ssh user_name@your_localhost")
os.chdir(path) # Specifying the path where the cloned project has to be copied
os.system(clone) # Cloning

print"\n CLONED SUCCESSFULLY.! \n"

Post a Comment for "Python Script To Git Clone Without Entering A Password At The Prompt"