---
# System prepended metadata

title: Git - git merge 分支合併
tags: [Git]

---

# Git - git merge 分支合併

## git merge 分支名
* **git merge 分支名** 用來合併分支
    目前我們有 **feature1** 與主幹 **master** 兩個分支
    ```git
    design1@DESKTOP-2SJKDSH MINGW64 ~/Desktop/Gene/project (feature1)
    $ git log
    commit 56575deaa1f1dccef76137003819ff8c6feb9aef (HEAD -> feature1)
    Author: Gene <gene.xxx@xxx.com.tw>
    Date:   Tue Feb 9 14:29:10 2021 +0800

        add css

    commit 68e8338c7d5fa82b702187e146f0323c0cb14186 (master)
    Author: Gene <gene.xxx@xxx.com.tw>
    Date:   Tue Feb 9 14:20:49 2021 +0800

        update index

    commit 016aa12061b8fd3317bd5e2d9e5b3e7da9915287
    Author: Gene <gene.xxx@xxx.com.tw>
    Date:   Tue Feb 9 14:19:21 2021 +0800

        add index
    ```
    若我們想要將 **feature1** 合併到 **master** 裡，我們需要先移動到 **master** 分支
    ```git
    design1@DESKTOP-2SJKDSH MINGW64 ~/Desktop/Gene/project (feature1)
    $ git checkout master
    Switched to branch 'master'
    M       index.html

    design1@DESKTOP-2SJKDSH MINGW64 ~/Desktop/Gene/project (master)
    $ git branch 
      feature1
    * master
    ```
    接著使用 **git merge feature1** 指令，將 **feature1** 合併到 **master** 
    (預設會使用 Fast-forward 方式合併)
    ```git
    design1@DESKTOP-2SJKDSH MINGW64 ~/Desktop/Gene/project (master)
    $ git merge feature1
    Updating 68e8338..56575de
    Fast-forward
     css/all.css | 0
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 css/all.css
    ```
    使用 **git log** 查看，可以看到 **feature1** 已經成功合併到 **master** 了
    ```git
    design1@DESKTOP-2SJKDSH MINGW64 ~/Desktop/Gene/project (master)
    $ git log
    commit 56575deaa1f1dccef76137003819ff8c6feb9aef (HEAD -> master, feature1)
    Author: Gene <gene.xxx@xxx.com.tw>
    Date:   Tue Feb 9 14:29:10 2021 +0800

        add css

    commit 68e8338c7d5fa82b702187e146f0323c0cb14186
    Author: Gene <gene.xxx@xxx.com.tw>
    Date:   Tue Feb 9 14:20:49 2021 +0800

        update index

    commit 016aa12061b8fd3317bd5e2d9e5b3e7da9915287
    Author: Gene <gene.xxx@xxx.com.tw>
    Date:   Tue Feb 9 14:19:21 2021 +0800

        add index
    ```
    
###### tags: `Git`