命令行下Git自动提交

17 篇文章 0 订阅
7 篇文章 0 订阅

Windows操作系统下

代码

注意,一下代码所在的文件夹需要添加到环境变量中

  • winPushGit.py
import sys,os

userName='你的GitHub用户名'
password='你的GitHub密码'

gitignore='''
venv
.idea
__pycache__
'''

def exeCmd(cmd):
    cmds=cmd.split('\n')
    for c in cmds:
        os.system(c)

if __name__ == '__main__':
    print('git init directory: ',sys.argv[1])
    dir=sys.argv[1]
    if os.path.exists(f'{dir}/.git'):#已经初始化
        pass
    else:
        with open('.gitignore', 'w') as f:
            f.write(gitignore)
        url=input('input github repository URL: ')
        if url=='':
            exit(0)
        suffix=url.replace('https://','')
        https=f'https://{userName}:{password}@{suffix}.git'
        cmd=f'''
            git init
            git remote add origin {https}
            '''
        exeCmd(cmd)
    #公操作
    cmd='''
        git add -A
        git commit -m "commit"
        git push origin master
        '''
    exeCmd(cmd)
  • pushGit.cmd
:: @echo off
python D:\codes\PycharmProjects\tool\winPushGit.py "%cd%"

使用方法

  1. 在GitHub新建一个repository(已经新建知识库可以忽略这一步)
  2. 找到需要添加的文件夹,按shift并按S打开命令行
  3. 输入:pushGit
  4. 如果是第一次提交,需要输入repository目录(图1)
  5. 提交完毕

图1

图1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值