Git常用命令记录

git status

查看仓库当前的状态,由下图我们可以知道,文件test2.txt被修改了。

git diff

我们想知道具体改了什么,可以用git diff [file],如果没有跟上file,则显示所有的不同

git log [–pretty=oneline]

--pretty=oneline 单行显示可以更清楚。从打印出来的信息来看,我们最近都有哪些提交,每次提交的commit信息都可以看到。

1
2
3
4
5
6
7
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
2f351739f3ae0cd24d48576316c8b6899827147b (HEAD -> master, origin/master, origin/HEAD) update test2
1df56aec78f9bd02045357531b20da8e33bdb09c (origin/master_cp) update test2.txt
2a0485da4201a08d897058ba6cf741d077ee7400 (help) add test2.txt
bbb00ff25b227acbf8fc0e5eb7c9536b2100312c add test.txt
a512263c770e4c5384c3943e78016173d81b5869 Initial commit
dengmx ~/blog/md/git/git_demo/git1/git_demo$

最前面的那一大串就是git commit的版本号了(commit id)。HEAD -> master 表示该版本为现在本地仓库的版本。origin/HEAD表示改版本为远程仓库的版本。可以看下图:

在添加aaa.txt文件之后,仅做了commit操作,并没有真正push到远程仓库。

接下来我们push到远程仓库:

origin/HEAD的位置发生了变化。

git reflog

用来记录你的每一次命令。

1
2
3
4
5
6
7
8
9
10
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git reflog
0e1afcf (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: moving to HEAD^
ae87611 HEAD@{1}: commit: add something into aaa.txt
0e1afcf (HEAD -> master, origin/master, origin/HEAD) HEAD@{2}: commit: add aaa.txt
2f35173 HEAD@{3}: commit: update test2
1df56ae (origin/master_cp) HEAD@{4}: merge master_cp: Fast-forward
2a0485d (help) HEAD@{5}: checkout: moving from master_cp to master
......
bbb00ff HEAD@{14}: commit: add test.txt
a512263 HEAD@{15}: clone: from https://gitee.com/_matthew/git_demo.git

退回到指定的commit id所在版本

还未push到远程仓库

aaa.txt文件新增了内容,并且已经进行了commit操作,还未push到远程仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
dengmx ~/blog/md/git/git_demo/git1/git_demo$ vi aaa.txt 
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git add .
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git commit -m 'add something into aaa.txt'
[master ae87611] add something into aaa.txt
1 file changed, 2 insertions(+)
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
ae87611bad1b9b185bead14e579b4753f42da8e0 (HEAD -> master) add something into aaa.txt
0e1afcf3b3eb42e04a09827a2d6a65bc60d25ec4 (origin/master, origin/HEAD) add aaa.txt
2f351739f3ae0cd24d48576316c8b6899827147b update test2
1df56aec78f9bd02045357531b20da8e33bdb09c (origin/master_cp) update test2.txt
2a0485da4201a08d897058ba6cf741d077ee7400 (help) add test2.txt
bbb00ff25b227acbf8fc0e5eb7c9536b2100312c add test.txt
a512263c770e4c5384c3943e78016173d81b5869 Initial commit

现在将本地仓库的回退到上一个版本。
首先,Git必须知道当前版本是哪个版本,在Git中,用HEAD表示当前版本,也就是最新的提交ae8761…,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。

1
2
git reset --hard HEAD^
HEAD is now at 0e1afcf add aaa.txt

根据提示,可以看到本地的HEAD已经指向了 0e1afcf…,我们再来看一下日志

1
2
3
4
5
6
7
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
0e1afcf3b3eb42e04a09827a2d6a65bc60d25ec4 (HEAD -> master, origin/master, origin/HEAD) add aaa.txt
2f351739f3ae0cd24d48576316c8b6899827147b update test2
1df56aec78f9bd02045357531b20da8e33bdb09c (origin/master_cp) update test2.txt
2a0485da4201a08d897058ba6cf741d077ee7400 (help) add test2.txt
bbb00ff25b227acbf8fc0e5eb7c9536b2100312c add test.txt
a512263c770e4c5384c3943e78016173d81b5869 Initial commit

可以看到刚才的那个commit id的记录已经不见了。

但是,后来我们又发现刚才那个版本没有问题,我们又需要回到刚才的那个版本,那又该如何操作呢?
我们可以借助于git reflog,查看到刚才的commit id

1
2
3
4
5
6
7
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git reflog
0e1afcf (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: moving to HEAD^
ae87611 HEAD@{1}: commit: add something into aaa.txt
0e1afcf (HEAD -> master, origin/master, origin/HEAD) HEAD@{2}: commit: add aaa.txt
2f35173 HEAD@{3}: commit: update test2
......
a512263 HEAD@{15}: clone: from https://gitee.com/_matthew/git_demo.git

可以找到刚才的commit idae87611,所以我们可以使用命令git reset --hard commit_id来穿梭到指定版本。

1
2
3
4
5
6
7
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git reset --hard ae87611
HEAD is now at ae87611 add something into aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
ae87611bad1b9b185bead14e579b4753f42da8e0 (HEAD -> master) add something into aaa.txt
0e1afcf3b3eb42e04a09827a2d6a65bc60d25ec4 (origin/master, origin/HEAD) add aaa.txt
......
a512263c770e4c5384c3943e78016173d81b5869 Initial commit

可以看到又回到了刚才做了commit操作之后的状态了。

已经push到远程仓库

前面我们已经讲了已经commit但是还未push的情况。现在我们来说说已经push的情况。
我们先进行push操作。将对aaa.txt的修改提交到远程仓库。

1
2
3
4
5
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
ae87611bad1b9b185bead14e579b4753f42da8e0 (HEAD -> master, origin/master, origin/HEAD) add something into aaa.txt
0e1afcf3b3eb42e04a09827a2d6a65bc60d25ec4 add aaa.txt
......
a512263c770e4c5384c3943e78016173d81b5869 Initial commit

还原提交到远程分支的commit id

1
2
3
4
5
6
7
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git revert ae87611bad1b9b185bea
[master 6f3e21d] Revert "add something into aaa.txt"
1 file changed, 2 deletions(-)
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
6f3e21d2001d16a2500aefa22478bc15493dd8aa (HEAD -> master) Revert "add something into aaa.txt"
ae87611bad1b9b185bead14e579b4753f42da8e0 (origin/master, origin/HEAD) add something into aaa.txt
......

可以看到 origin/HEAD所在的commit id还是 ae87611b....,但是新增加了一个commit id 6f3e21d20...,并且
本地的指针HEAD -> master指向该commit id。所以,我们已经可以知道撤销已经push的的commit的方法是通过一个commit操作来回到上次push时的版本。

所以我们进行push,来将刚才push的给撤销:

1
2
3
4
5
6
7
8
9
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git push
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 308 bytes | 308.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/_matthew/git_demo.git
ae87611..6f3e21d master -> master

查看下日志:

1
2
3
4
5
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git log --pretty=oneline
6f3e21d2001d16a2500aefa22478bc15493dd8aa (HEAD -> master, origin/master, origin/HEAD) Revert "add something into aaa.txt"
ae87611bad1b9b185bead14e579b4753f42da8e0 add something into aaa.txt
......
dengmx ~/blog/md/git/git_demo/git1/git_demo$

可以看到origin/HEAD已经指向6f3e21d2001d...。并且通过git的web页面也可以看到刚才push上来的内容已经不见了。回退成功。

关于(本地)工作区和版本库

工作区

工作区就是电脑里能看到的目录,比如我的git_demo文件夹就是一个工作区:

1
2
3
4
5
6
7
8
9
dengmx ~/blog/md/git/git_demo/git1/git_demo$ ll -ah
total 32
drwxr-xr-x 7 apple staff 224B Dec 1 21:37 .
drwxr-xr-x 3 apple staff 96B Dec 1 14:40 ..
drwxr-xr-x 15 apple staff 480B Dec 1 21:43 .git
-rw-r--r-- 1 apple staff 902B Dec 1 14:40 README.md
-rw-r--r-- 1 apple staff 6B Dec 1 21:37 aaa.txt
-rw-r--r-- 1 apple staff 6B Dec 1 14:48 test1.txt
-rw-r--r-- 1 apple staff 59B Dec 1 20:02 test2.txt

版本库

工作区有一个隐藏目录.git,它不算工作区,而是Gid的版本库。从上面我们也可以看到。
版本库由暂存区分支组成,创建Git版本库时,Git会自动为我们创建一个master分支,所以,现在git commit就是往master分支上提交更改。

所以git add是把文件修改添加到暂存区;用git commit提交更改时,实际上就是把暂存区的所有内容提交到当前分支。

因此,git commit提交的对象是暂存区中的被修改的文件。

比如第一次修改后,接着git add .,然后又发生了第二次修改,此时直接git commit操作。只会将第一次的修改提交,而第二次的修改必须在你git add .之后再提交才会被提交。

git add之前撤销和git commit之前撤销

git add之前撤销

修改后,还未进行git add操作,则修改还未提交到暂存区,仍在工作区。使用命令git checkout -- <file>,注意--和空格,撤销了本次修改。git checkout -- .表示撤销当前工作区下的全部修改,恢复到和版本库一致。

1
2
3
4
5
6
7
8
9
10
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt 
first
dengmx ~/blog/md/git/git_demo/git1/git_demo$ echo 'hello world!!!' >> aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt
first
hello world!!!
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git checkout -- aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt
first
dengmx ~/blog/md/git/git_demo/git1/git_demo$

git commit之前撤销

修改后已经进行了git add操作,则修改已经提交到暂存区中。现在我们要撤销它,可以先将该修改从暂存区移出,然后我们再进行和【git add之前撤销】一样的操作,看下面的命令,我们用git status查看我们每步操作之后的状态:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt # 初始内容
first
dengmx ~/blog/md/git/git_demo/git1/git_demo$ echo 'hello world!!!' >> aaa.txt # 修改
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt
first
hello world!!!
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status # 状态为已经修改
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: aaa.txt

no changes added to commit (use "git add" and/or "git commit -a")
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git add aaa.txt # git add 到暂存区
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status # 状态为等待git commit
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: aaa.txt

dengmx ~/blog/md/git/git_demo/git1/git_demo$ git reset HEAD aaa.txt # 从暂存区撤销
Unstaged changes after reset:
M aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: aaa.txt

no changes added to commit (use "git add" and/or "git commit -a")
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt # 暂存区撤销,但是工作区还是没撤销
first
hello world!!!
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git checkout -- aaa.txt # 从工作区撤销
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt # 最后结果文件,撤销成功
first

删除文件

1
dengmx ~/blog/md/git/git_demo/git1/git_demo$ rm test1.txt  # 工作区删除文件 test1.txt

接下来可进行的操作为 git add/rm <file>, addrm都能完成删除文件的功能。或是 git checkout -- <file>进行撤销操作。
这儿我们选择git rm操作。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status   
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

deleted: test1.txt

no changes added to commit (use "git add" and/or "git commit -a")
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git rm test1.txt # 将本次修改(删除也是一种修改操作)提交到暂存区。
rm 'test1.txt'
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

deleted: test1.txt

将本次修改提交到版本库的分支:

1
2
3
4
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git commit 
[master 09d676a] rm test1.txt
1 file changed, 1 deletion(-)
delete mode 100644 test1.txt

将本次修改提交到远程仓库的分支:

1
2
3
4
5
6
7
8
9
10
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git push
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 230 bytes | 230.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Powered by Gitee.com
To https://gitee.com/_matthew/git_demo.git
6f3e21d..09d676a master -> master
dengmx ~/blog/md/git/git_demo/git1/git_demo$

文件成功删除。

本地无项目,克隆并修改提交到远程分支流程

Git 全局配置

1
2
git config --global user.name "邓明雄"
git config --global user.email "dengmx@getui.com"

克隆,修改,提交,最后推送到远程分支

1
2
3
4
5
6
git clone git@dev-gitlab.getui.net:dengmx/test.git
cd test
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

项目在本地,需要提交到git远程的指定分支

进入项目目录,初始化git仓库,将本地git仓库的分支与git远程分支关联,提交修改,最后推送到远程分支。远程库的名字就是origin,这是Git默认的叫法,当然也可以改成别的。

1
2
3
4
5
6
cd existing_folder
git init
git remote add origin git@dev-gitlab.getui.net:dengmx/test.git
git add .
git commit -m 'first commit'
git push -u origin master

由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令(git push即可)。

一般项目定制开发流程

1.从git上拉取指定分支

1
git clone git@dev-gitlab.getui.net:dengmx/test.git

2.开发,进入工程目录,新增文件

1
2
3
cd test
echo 'test1'> test1.txt
...

3.提交到指定分支[默认分支(master)]
这儿我们先提交到一个新的分支,再merge到主分支。

3.1 首先我们先将当前分支(master)复制成一个新的分支(master_cp)

1
git branch -c master_cp

3.2 查看当前所有分支和当前所处分支(颜色不一样并且前面带*号):

1
git branch

3.3 转到新分支

1
git checkout master_cp

3.4 提交到新分支

1
2
3
git add .
git commit -m 'xxx'
git push origin master_cp

此时,git会先新建分支master_cp,再将文件提交到该分支

4.最后再merge到主分支(master)


切换回master分支:

1
git checkout master

将在分支master_cp上做的改动merge到分支master

1
git merge master_cp

默认的合并策略是Fast forward模式,使用--no-ff参数,表示禁用 Fast forward,用普通模式合并,合并后的历史有分支,能看出来曾经做过合并。因为这样要创建一个新的commit,所以加上-m参数,把commit描述写进去。而Fast forward合并就看不出来曾经做过合并。
完整命令如下:

1
git merge --no-ff -m "merge with no-ff" master_cp

git merge命令用于合并指定分支到当前分支。现在本地 master和master_cp就一样了。
但是还没有提交,所以我们接着去提交改动到git仓库的master分支

1
git push origin master

做好开发工作后,代码也提交到了master,那么我们可以删除 master_cp分支

删除本地仓库的master_cp分支

1
git branch -d master_cp

但是远程仓库的并没有删除,可以用下面的命令删除远程仓库的master_cp分支

1
git push origin --delete master_cp

用命令git log --graph --pretty=oneline --abbrev-commit更友好的展示分支的合并情况

修复分支bug

当我们正在dev分支上开发,突然发现了master分支上的一个bug,但是我们开发还是进行了一半,还不能提交,那么如何来修复这个bug呢?
步骤如下:
1.在dev上开发到一半,不commit操作的话不能切换到新分支去修复bug,因此我们可以先用命令git stash暂存dev分支的修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt 
first
dengmx ~/blog/md/git/git_demo/git1/git_demo$ echo 'dev aaa.txt'>> aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt
first
dev aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status
On branch dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: aaa.txt

no changes added to commit (use "git add" and/or "git commit -a")
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git checkout master
error: Your local changes to the following files would be overwritten by checkout:
aaa.txt
Please commit your changes or stash them before you switch branches.
Aborting

dengmx ~/blog/md/git/git_demo/git1/git_demo$ git stash
Saved working directory and index state WIP on dev: 503dfca rm test2.txt

查看stash记录列表

1
2
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git stash list
stash@{0}: WIP on dev: 503dfca rm test2.txt

2.现在可以切换到master

1
2
3
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

3.新建分支issue-1.1.1,在该分支上修复bug,并提交

1
2
3
4
5
6
7
8
9
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git checkout -b issue-1.1.1
Switched to a new branch 'issue-1.1.1'
dengmx ~/blog/md/git/git_demo/git1/git_demo$ echo 'fix bug in master' >> aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt
first
fix bug in master

dengmx ~/blog/md/git/git_demo/git1/git_demo$ git add aaa.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git commit -m 'fix bug in master'

4.切换回master,merge到远程master分支

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
git merge --no-ff -m "merged bug fix master-1.1.1" issue-1.1.1
```

5.很快解决了bug。现在,是时候回到dev分支了
```bash
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git checkout dev
Switched to branch 'dev'
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git status # 因为我们已经git stash暂存了,所以现在工作区还是干净的。
On branch dev
nothing to commit, working tree clean
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git stash list # 查看已经暂存的版本列表
stash@{0}: WIP on dev: 503dfca rm test2.txt
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git stash pop # 与git stash apply的区别是,pop 恢复的同时会把stash内容也删掉
On branch dev
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: aaa.txt

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (6bd002c8575c43886080567e0fc3ab1562073d76)

6.继续在dev上搬砖吧…

多人协作时代码冲突问题

假设一起在dev分支上开发,在提交前先pull,但是pull之前需要确保当前本地dev分支已经与远程dev分支关联

1
git branch --set-upstream-to=origin/dev dev

拉取远程最新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://gitee.com/_matthew/git_demo
9d49e44..cae9d5b dev -> origin/dev
Auto-merging aaa.txt
CONFLICT (content): Merge conflict in aaa.txt
Automatic merge failed; fix conflicts and then commit the result.

dengmx ~/blog/md/git/git_demo/git1/git_demo$ cat aaa.txt # 查看冲突文件内容
first
fix bug in master
<<<<<<< HEAD
git_demo add something,too!!!
=======
git_demo2 add something!
>>>>>>> cae9d5b6c8ecfded6274eb9452cf79544a225657

修改冲突,将 aaa.txt 改为以下内容

1
2
3
4
first
fix bug in master
git_demo add something,too!!!
git_demo2 add something!

再进行提交

1
2
3
git add aaa.txt
git commit -m 'fix changes'
git push origin dev

其它

查看远程库的信息
1
2
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git remote
origin

或者,用git remote -v显示更详细的信息:

1
2
3
dengmx ~/blog/md/git/git_demo/git1/git_demo$ git remote -v
origin https://gitee.com/_matthew/git_demo.git (fetch)
origin https://gitee.com/_matthew/git_demo.git (push)

上面显示了可以抓取和推送的origin的地址。如果没有推送权限,就看不到push的地址。

推送分支

推送分支,就是把该分支上的所有本地提交推送到远程库。推送时,要指定本地分支,这样,Git就会把该分支推送到远程库对应的远程分支上:

1
$ git push origin master

如果要推送其他分支,比如dev,就改成:

1
$ git push origin dev

最后推荐两个web端学习网站
  1. 廖雪峰Git教程
  2. Pro Git Book