Skip to content

Commit 5e09ea2

Browse files
committed
add shell for github
1 parent 2386068 commit 5e09ea2

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# 封装一些GitHub常用命令
2+
3+
4+
我们在日常的开发过程中,肯定会经常要用到一些代码版本控制工具,其中较为常用的如GitHub,当然GitHub的命令已经比较精简了,不过依照我们每个人的个人习惯不同还是可以进行一些简单的封装的。
5+
6+
## 封装一些适用于**某个项目**的命令
7+
8+
比如说,我最近一直在维护一个开源的[Android笔记的项目](https://github.com/linsir6/AndroidNote),这样我每天可能都会有很多次的提交,每次提交可能输入的都是那么几个命令:
9+
10+
```
11+
cd /Users/mac/WorkSpace/git_android_notes
12+
git pull
13+
git add .
14+
git commit -m "description"
15+
git push origin master
16+
```
17+
18+
虽然命令不是非常复杂,但是每次都需要手动输入,还是很麻烦的,所以如果我们能将其封装成一句命令就非常nice了,例如:
19+
20+
```
21+
push description XXX XXX
22+
```
23+
24+
其实做这样一个封装是非常简单的,但是可以帮我们省很多事情。
25+
如果您对Shell的基本命令还不是很了解,请参考[Shell脚本入门](https://github.com/linsir6/AndroidNote/blob/master/Shell%E8%84%9A%E6%9C%AC%E7%9B%B8%E5%85%B3/%E4%B8%80%E7%AF%87%E6%96%87%E7%AB%A0%E5%AD%A6%E6%87%82Shell%E8%84%9A%E6%9C%AC.md)
26+
27+
我们看一下,shell脚本的代码:
28+
29+
```
30+
cd /Users/mac/WorkSpace/git_android_notes
31+
32+
echo "begin it ..."
33+
34+
git pull
35+
git add .
36+
37+
git commit -m "$*"
38+
39+
echo $*
40+
41+
git push origin master
42+
43+
echo "finish it ..."
44+
```
45+
46+
只要通过这样简单的封装,我们就可以实现我们,一行命令上传脚本的想法啦~
47+
48+
49+
## 封装一些具有普适性的代码
50+
51+
- **进入到工作空间目录**
52+
53+
封装前: ``cd /Users/mac/WorkSpace``
54+
封装后: ``. me``
55+
56+
shell脚本代码:
57+
58+
```
59+
cd ~/WorkSpace
60+
```
61+
62+
----
63+
64+
- **拉取远程仓库代码**
65+
66+
封装前: ``git pull 或 git pull origin XXX``
67+
封装后: ``pull 或 pull XXX``
68+
69+
shell脚本代码:
70+
71+
```
72+
if [ "$1" = "" ]
73+
then
74+
git branch --set-upstream-to=origin/master master
75+
git pull
76+
77+
else
78+
git pull origin $1
79+
fi
80+
```
81+
82+
----
83+
84+
- **提交代码到远程仓库**
85+
86+
封装前:
87+
88+
```
89+
git pull
90+
git add .
91+
git commit -m "description"
92+
git push origin master
93+
```
94+
95+
封装后: ``push master "description"``
96+
97+
shell脚本代码:
98+
99+
```
100+
git pull
101+
git add .
102+
temp=$1
103+
shift
104+
git commit -m "$*"
105+
git push origin $temp
106+
```
107+
108+
----
109+
110+
当然,这里面只介绍了几种简单的封装,大家可以按照自己的需求,进行一些封装~
111+
112+
113+
114+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Android-Note里面记录了有关Android的常用基础知识、面试中经常
135135
## GitHub相关
136136

137137
- [GitHub基础操作](/GitHub相关/GitHub基础操作.md)
138+
- [封装一些GitHub常用命令](/GitHub相关/封装一些GitHub常用命令.md)
138139

139140
----
140141

0 commit comments

Comments
 (0)