gitpython使用用户和密码进行git身份验证 [英] gitpython git authentication using user and password

查看:2217
本文介绍了gitpython使用用户和密码进行git身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GitPython,但没有找到使用用户名和密码推送回购的方法.有人可以给我发送一个可行的示例,也可以给我一些如何做的建议吗? 我需要做的是: 将文件添加到存储库,然后使用提供的用户名和密码将其推送.

I'm using GitPython but did not find a way to push to repo using username and password. Can anybody send me a working example or give me some pointer about how to do it? What I need to do is: add a file to the repository, push it using the username and password provided.

推荐答案

这就是我自己用来拉动的东西

This is what I used for myself for pulling

#! /usr/bin/env python3

import git
import os
from getpass import getpass

project_dir = os.path.dirname(os.path.abspath(__file__))
os.environ['GIT_ASKPASS'] = os.path.join(project_dir, 'askpass.py')
os.environ['GIT_USERNAME'] = username
os.environ['GIT_PASSWORD'] = getpass()
g = git.cmd.Git('/path/to/some/local/repo')
g.pull()

askpass.py(与此类似)

此目录与pull.py在同一目录中,不仅限于Github.

askpass.py (similar to this one)

This is in the same directory as pull.py and is not limited to Github only.

#!/usr/bin/env python3
#
# Short & sweet script for use with git clone and fetch credentials.
# Requires GIT_USERNAME and GIT_PASSWORD environment variables,
# intended to be called by Git via GIT_ASKPASS.
#

from sys import argv
from os import environ

if 'username' in argv[1].lower():
    print(environ['GIT_USERNAME'])
    exit()

if 'password' in argv[1].lower():
    print(environ['GIT_PASSWORD'])
    exit()

exit(1)

这篇关于gitpython使用用户和密码进行git身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆