git實戰筆記系列:GitHub創建新分支及合併、常用git命令

聲明:本教程不收取任何費用,歡迎轉載請註明出處,尊重作者勞動成果,不得用於商業用途,侵權必究!!!

 

一、GitHub創建新分支及合併

 

測試的github項目地址:https://github.com/yyhLum/vue-cli-project-template

在項目 README.md 中,添加如下文字 

 

然後添加新的分支 yyh,並進行提交

MacBook-Pro:vue-cli-project-template luminal$ 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:   README.md
 
no changes added to commit (use "git add" and/or "git commit -a")
MacBook-Pro:vue-cli-project-template luminal$ git checkout -b yyh
M       README.md
Switched to a new branch 'yyh'
MacBook-Pro:vue-cli-project-template luminal$ git branch
  master
* yyh
MacBook-Pro:vue-cli-project-template luminal$ git add .
MacBook-Pro:vue-cli-project-template luminal$ git commit -m "新分支yyh"
[yyh 57c187f] 新分支yyh
1 file changed, 1 insertion(+)
MacBook-Pro:vue-cli-project-template luminal$ git push origin yyh
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 305 bytes | 305.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote:
remote: Create a pull request for 'yyh' on GitHub by visiting:
remote:
remote:
remote:
remote: GitHub found 4 vulnerabilities on yyhLum/vue-cli-project-template's default branch (1 high, 2 moderate, 1 low). To find out more, visit:
remote:
* [new branch]      yyh -> yyh
MacBook-Pro:vue-cli-project-template luminal$

 

只有執行命令:git push origin yyh

提交的時候纔會在github服務端上創建一個分支,如下圖:

    

 

然後查看 README.md 文件,如下圖:

 

我們需要把 yyh分支合併到 master分支中去。可以看到上面有一個 Pull requests,拉取請求,

現在要做的就是將 yyh分支上所有的數據拉取到 master分支上。點擊 Pull requests  

 

如上圖中,編號1的框中提示的意思就是有需要合併的分支,需要拉取一下。

但是有的時候是不會提示的,那麼這裏就用沒有提示的情況去演示怎樣合併。

編號2的框是創建一個新的拉取,點開

 

兩個框,代表的意義爲,想要將2號框中的分支的數據合併到1號框中的分支中去。

那麼,我們肯定不能是從 master 到 master,是要從 yyh到 master,所以2號框要選擇 yyh分支

 

看1,對鉤的意思就是可以合併,沒有衝突。就可以點create pull request,創建一個拉取請求

 

這裏是填寫本次更新的信息,填寫完畢之後就可以創建了。

 

    

可以看到,綠色對鉤,這就表明上面的一系列操作成功了。

分別點擊:merge pull request 合併拉取請求、 confirm merge 確認合併

 

當然這個時候,你還可以撤銷,點擊Revert 還原。

如果沒有點擊Revert ,現在我們可以回到 code 去看看 master分支(主分支)的合併效果了。

 

 

二、常用 git 命

git branch

查看當前分支情況

 

git branch yyh

創建yyh分支 

 

git checkout yyh

切換分支yyh 

 

git checkout -b yyh

本地創建yyh分支,同時切換到yyh分支。

只有執行命令:git push origin yyh

提交的時候纔會在github服務端上創建一個分支

 

 

 

參考鏈接:

GitHub分支創建及合併

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章