我本人一直在写一些玩具代码的时候,有提交到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