【实用小软件】通过gitPython实现对git配置和拉取

    ​致力于将操作简单化,懒人化的我在项目的契机下完成了部分使用python操作git,同时为了让测试人员随时随地都能拉取​git分支特意开发的一个小软件。

​项目结构:

​配置信息:

start.exe拉取界面​:(注意本地分支默认为dev_lin,暂时不支持修改。如果下载失败,可以手动删除配置里本地拉取地址的目录)

拉取分支代码​如下:

 1     myDir = dict_config['locl_dir']
 2       if os.path.exists(myDir):
 3         repo = Repo(myDir)
 4       else:
 5         repo = Repo.init(myDir)
 6       username = dict_config['username']
 7       password = dict_config['password']
 8       giturl_end = dict_config['git_url'].split("https://")[1]
 9       branch = dict_config['branch']
10       giturl = f"https://{username}:{password}@"+giturl_end
11       #如果当前远程库无法获取,则建立联系。自动更新
12       if repo.remotes == []:
13         origin = repo.create_remote('origin', giturl)
14 15       #如果有,则直接获取我们想要的远程库。自动更新最新代码
16       else:
17         origin = repo.remote('origin')
18         print(origin)
19 20       #刷新获取分支
21       origin.fetch()
22       #查看是否关联到远程分支
23       print(origin.refs)
24 25       if origin.refs == []:
26         #创建关联远程分支的本地分支  创建本地分支,选择分支,切换分支   origin.refs.dev_lin 本地分支名
27         repo.create_head(branch, origin.refs.dev_lin).set_tracking_branch(origin.refs.dev_lin).checkout()
28 29       #拉取分支
30       repo.remote().pull(branch)

拉取软件下载地址:

​https://pan.baidu.com/s/1jUsRgD-6HTgzd6xPOjS9GQ 提取码: tb4w 复制这段内容后打开百度网盘手机App,操作更方便哦

一切博文基本原创,谢谢
原文地址:https://www.cnblogs.com/mumushizhige/p/15602535.html