GitPython使用脚本中的电子邮件和密码

2024-06-28 11:57:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我必须添加我的用户并将github传递到代码中。有可能吗? 我的意思是每次运行脚本时都需要登录,但使用代码中的用户和密码:

代码:

from git import Repo

def add_files():
    user = 'martinbouhier'
    pass = '123pass'
    repo_dir = 'python'
    if os.path.exists(repo_dir):
        shutil.rmtree(repo_dir)
    git_url = 'https://github.com/martinbouhier/python'
    Repo.clone_from(git_url, repo_dir)
    shutil.copy(file_klip, repo_dir)
    os.remove(file_klip)
    os.chdir(repo_dir)
    repo = Repo()
    commit_message = 'Actualizacion'
    repo.index.add([file_klip])
    repo.index.commit(commit_message)
    origin = repo.remote('origin')
    origin.push()

Tags: 代码用户fromgitgithubaddosdir