两则快速git pull push的脚本

在团队中使用git有一段时间了,强烈到领悟的git的方便,方便地认为这个世界上只需要git,不需要svn这样的东东。
然而,即使在方便的工具也有遇到不方便的瓶颈的时候,举例来说,git pull 和push的语法基本都是差不多,基本上是我们需要输入origin branchName
可不可以直接填写上origin 和 当前的分支名呢,这样不是更方便么,当然可以。请参考下列代码:
gpull.py 
#!/usr/bin/env python
# coding=utf-8
from subprocess import Popen,PIPE,STDOUT
from os import system


def gpull():
    branchColorRule = readFromShell('git config color.branch')
    if ('always' == branchColorRule):
        system('git config color.branch auto')


    getBranch = "git branch | sed -n '/\* /s///p'"
    gitBranch = readFromShell(getBranch)
    command = 'git pull origin %s'%(gitBranch)
    print command
    system(command)
    if ('always' == branchColorRule):
        system('git config color.branch always')




def readFromShell(command):
    p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
    result = p.stdout.read().strip()
    return result


gpull()



gpush.py

#!/usr/bin/env python
# coding=utf-8
from subprocess import Popen,PIPE,STDOUT
from os import system


def gpush():
    branchColorRule = readFromShell('git config color.branch')
    if ('always' == branchColorRule):
        system('git config color.branch auto')


    getBranch = "git branch | sed -n '/\* /s///p'"
    gitBranch = readFromShell(getBranch)
    command = 'git push origin %s'%(gitBranch)
    print command
    system(command)
    if ('always' == branchColorRule):
        system('git config color.branch always')




def readFromShell(command):
    p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
    result = p.stdout.read().strip()
    return result


gpush()


仓库地址: https://github.com/androidyue/DroidPy
关于为什么处理git status color always 情况,因为如果不处理,得到的不是一个Plain Text的分支(带着颜色),这样会导致无法使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值