GitHub再入門（ブランチ操作）

# ブランチ操作
[1. ブランチ作成](http://qiita.com/qio9o9/private/6baa7059b0e49aa975d4#1-%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E4%BD%9C%E6%88%90)
![img-branch.png](https://qiita-image-store.s3.amazonaws.com/0/195839/d17e3578-367c-6397-71c2-4b0a41f97e39.png)

[2. ブランチ切り替え](http://qiita.com/qio9o9/private/6baa7059b0e49aa975d4#2-%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E5%88%87%E3%82%8A%E6%9B%BF%E3%81%88)
![img-checkout.png](https://qiita-image-store.s3.amazonaws.com/0/195839/4deac9bb-1ae8-56af-ebe5-ab58c0bd1471.png)

[3. ブランチ削除](http://qiita.com/qio9o9/private/6baa7059b0e49aa975d4#3-%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E5%89%8A%E9%99%A4)
![img-branch-d.png](https://qiita-image-store.s3.amazonaws.com/0/195839/270b2659-7f24-9d92-a4bc-217107e84cfc.png)

[4. ブランチマージ](http://qiita.com/qio9o9/private/6baa7059b0e49aa975d4#4-%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E3%83%9E%E3%83%BC%E3%82%B8)

[4-1. fast-forward](http://qiita.com/qio9o9/private/6baa7059b0e49aa975d4#4-1-fast-forward)
![img-merge.png](https://qiita-image-store.s3.amazonaws.com/0/195839/9d22e71b-fa9b-2c56-67e1-63b979e1e0e8.png)

[4-2. non-fast-forward](http://qiita.com/qio9o9/private/6baa7059b0e49aa975d4#4-2-non-fast-forward)
![img-manual-merge.png](https://qiita-image-store.s3.amazonaws.com/0/195839/f7574eff-b274-1e2d-599e-4f054dcf6067.png)

## 1. ブランチ作成
```cmd:cmd
rm -rf .git/
git init
echo "# create(master)" > file_1.md
git add .
git commit -m "create@master"
echo "# update(master)" >> file_1.md
git commit -a -m "update@master"
git branch issue-1
git branch
```
![img-branch.png](https://qiita-image-store.s3.amazonaws.com/0/195839/d17e3578-367c-6397-71c2-4b0a41f97e39.png)

![branch.png](https://qiita-image-store.s3.amazonaws.com/0/195839/38ba59cc-d2bd-8d6b-e4cf-e981e1d419a9.png)


## 2. ブランチ切り替え
```cmd:cmd
git checkout issue-1
git branch
```
![img-checkout.png](https://qiita-image-store.s3.amazonaws.com/0/195839/4deac9bb-1ae8-56af-ebe5-ab58c0bd1471.png)

![checkout.png](https://qiita-image-store.s3.amazonaws.com/0/195839/caceeedd-3cc5-ada1-3aee-f3c5af5f71e9.png)

## 3. ブランチ削除
```cmd:cmd
git branch -d issue-1
git branch
```
![img-branch-d.png](https://qiita-image-store.s3.amazonaws.com/0/195839/270b2659-7f24-9d92-a4bc-217107e84cfc.png)

![branch-d.png](https://qiita-image-store.s3.amazonaws.com/0/195839/be4d0c9c-1b4a-8e36-eb38-291f680a5ce4.png)

## 4. ブランチマージ

### 4-1. fast-forward
**1. ブランチ（issue-1）作成**

```cmd:cmd
rm -rf .git/
git init
echo "# create(master)" > file_1.md
git add .
git commit -m "create@master"
echo "# update(master)" >> file_1.md
git commit -a -m "update@master"
git branch issue-1
git branch
git checkout issue-1
```
![img-branch.png](https://qiita-image-store.s3.amazonaws.com/0/195839/8a405ab6-37c4-5964-0ba1-7479fe374f16.png)
![img-checkout.png](https://qiita-image-store.s3.amazonaws.com/0/195839/36f02550-2b46-1248-83c0-894dde9a5d84.png)

**2. issue-1の編集＆マージ**

```cmd:cmd
echo "# update(issue-1)" >> file_1.md
git commit -a -m "update@issue-1"
cat file_1.md
git checkout master
cat file_1.md
git merge issue-1
cat file_1.md
git branch -d issue-1
git log --graph
```
![img-merge-2.png](https://qiita-image-store.s3.amazonaws.com/0/195839/941b3071-a279-4f2b-b0a3-ab298e874cb8.png)
![img-branch-d.png](https://qiita-image-store.s3.amazonaws.com/0/195839/7107063b-220f-516f-52c6-e2b8a7bd5285.png)

![merge.png](https://qiita-image-store.s3.amazonaws.com/0/195839/bf4691b2-b043-1a8b-9c90-99fc516e234d.png)

#### 4-2. non-fast-forward
**1. ブランチ（issue-1、issue-2）作成**

```cmd:cmd
rm -rf .git/
git init
echo "# create(master)" > file_1.md
git add .
git commit -m "create@master"
echo "# update(master)" >> file_1.md
git commit -a -m "update@master"
git branch issue-1
git branch issue-2
git branch
git checkout issue-1
```
![non-fast-1.png](https://qiita-image-store.s3.amazonaws.com/0/195839/7ea6c235-123e-cc34-b993-47d467639bbf.png)

**2. issue-1の編集＆マージ**

```cmd:cmd
echo "# update(issue-1)" >> file_1.md
git commit -a -m "update@issue-1"
cat file_1.md
git checkout master
cat file_1.md
git merge issue-1
cat file_1.md
git branch -d issue-1
```
![non-fast-2.png](https://qiita-image-store.s3.amazonaws.com/0/195839/7c34a480-962a-66a6-678d-f55109a4ec68.png)

**3. issue-2の編集＆マージ → 競合**

```cmd:cmd
git checkout issue-2
echo "# update(issue-2)" >> file_1.md
git commit -a -m "update@issue-2"
cat file_1.md
git checkout master
git merge issue-2
cat file_1.md
```
![non-fast-3.png](https://qiita-image-store.s3.amazonaws.com/0/195839/71f65313-192b-3696-9ad8-855114c67356.png)

![img-conflictpng.png](https://qiita-image-store.s3.amazonaws.com/0/195839/d4011ac9-c162-e647-53be-6ae315f52b90.png)

**4. issue-2競合の解消＆マージ**

```cmd:cmd
vi file_1.md
git commit -a -m "manual merge"
git branch -d issue-2
git log --graph
```
![non-fast-4.png](https://qiita-image-store.s3.amazonaws.com/0/195839/8a580f5a-36e8-8a9f-07b6-e836aae8b5ea.png)

![manual-merge.png](https://qiita-image-store.s3.amazonaws.com/0/195839/3c1f2cac-ad36-edf9-5f0b-0357da5067cc.png)