git 简单操作流程

​ 简单记录下 git 操作流程

拉取远程 master
$ git clone [email protected]:XM-Resource/Ebooks.git
创建本地分支+切换
$ git checkout -b add_foo_328
Switched to a new branch 'add_foo_328'
切换分支
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

$ git checkout add_foo_328
Switched to branch 'add_foo_328'

查看状态
$ git status
On branch add_foo_328
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:    LICENSE

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    README.md
    context.txt
    心理学/
    文学/
    计算机/

no changes added to commit (use "git add" and/or "git commit -a")
添加改动并提交
//添加改动
$ git add .
# On branch: add_foo_328  |  [*] => $e*
#
➤ Changes to be committed
#
#        deleted:  [1] LICENSE
#       new file:  [2] README.md
#       new file:  [3] context.txt
                ...
#       new file: [24] 计算机/机器学习/机器学习实践.mobi
#       new file: [25] 计算机/机器学习/机器学习:实用案例解析.mobi

// 查看状态确认
$ git status
On branch add_foo_328
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    deleted:    LICENSE
    new file:   README.md
    new file:   context.txt
    ...
    new file:   计算机/机器学习/机器学习实践.mobi
    new file:   计算机/机器学习/机器学习:实用案例解析.mobi

// 提交修到本地仓库
$ git commit -m "add new book"
[add_foo_328 4e31f83] add new book
 25 files changed, 62 insertions(+), 201 deletions(-)
 delete mode 100644 LICENSE
 create mode 100644 README.md
 create mode 100644 context.txt
 ...
 create mode 100644 计算机/机器学习/机器学习实践.mobi
 create mode 100644 计算机/机器学习/机器学习:实用案例解析.mobi

// 查看状态确认
$ git status
On branch add_foo_328
nothing to commit, working tree clean

合并master
// 切换到 master,先更新 master 防止 master 已被更新
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

// 先拉去远端 master 到本地
$ git fetch origin

// 把拉去的远端分支合并到本地 master 分支
$ git merge origin/master
Already up to date.

// 切换到自己的分支,并把 master 合并过来
$ git checkout add_foo_328
Checking out files: 100% (25/25), done.
Switched to branch 'add_foo_328'

// 更新本地 master 到分支,完成合并
$ git merge master
Already up to date.

// git log 查看(合并之后自己的分支在 master 之前)
$ git log --oneline --decorate --graph --all
* 4e31f83 (HEAD -> add_foo_328) add new book
* 2b1cdf5 (origin/master, origin/HEAD, master) Initial commit

// 提交合并之后的分支到远端仓库

提交分支到远程
// 查看当前的本地分支与远程分支的关联关系(只有本地 master和远程 [origin/master]关联)
$ git branch -vv
* add_foo_328 4e31f83 add new book
  master      2b1cdf5 [origin/master] Initial commit

// 添加远程分支
$ git remote add orign/add_foo [email protected]:XM-Resource/Ebooks.git

$ git remote -vv
origin  [email protected]:XM-Resource/Ebooks.git (fetch)
origin  [email protected]:XM-Resource/Ebooks.git (push)
orign/add_foo   [email protected]:XM-Resource/Ebooks.git (fetch)
orign/add_foo   [email protected]:XM-Resource/Ebooks.git (push)

$ git push orign/add_foo

github 上提交合并请求

进入 github 页面可以看到有新的提交需要合并到 master。

请求

点击进去如下:

合并

提交合并即可。