您的位置:首页 > 运维架构 > Shell

使用UNIX环境下的bash脚本自动化提交仓库到github

2017-01-22 23:58 162 查看
我本人一直在写一些玩具代码的时候,有提交到github上备份的习惯,由于这个是我自己写的玩具代码,也不涉及到多个分支,所以每次都是机械的敲一串相同的命令,为了提高生产力,在Mac的UNIX环境下写一个bash脚本,自动化每次提交到github,我每次只需要执行这个脚本就行了,下面给出源码:

#!/bin/bash

echo "start git add commit fetch merge push"
echo "git add -A"
git add -A

echo "git commit -m 'leetcode-louyuting'"
git commit -m 'leetcode-louyuting'

echo "git fetch origin master"
git fetch origin master

echo "git merge origin/master"
git merge origin/master

echo "git push origin master:master"
git push origin master:master


这个脚本大大提交了我的生产效率。

改进

上面的脚本没法设置commit的注释,采用的统一的注释,所以后面优化了下,采用动态设置commit注释的方式脚本如下:

#!/bin/bash

echo "git add ."
git add .

echo "git commit"
echo "请输入commit的注释信息:"
comment="commit new code"
read comment
git commit -m "$comment"

echo "git fetch origin master"
git fetch origin master

echo "git merge origin/master"
git merge origin/master

echo "git push origin master:master"
git push origin master:master
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git bash