# Local Branches

Time to branch out!

Fight the urge not to branch.

Git was designed for frequent branching and merging.

```bash
]$ git checkout -b feature-x
```

To view all of the branches, and see which one you are actively working:

```bash
]$ git branch
```

To switch between existing branches

```bash
]$ git checkout [branch-name]
```

Make changes and commit (like usual)

Done with your feature? Time to merge back into 'master'

First, let's view our diff's (assuming we are still on the feature-x branch)

```bash
]$ git diff master
```

Diffs look ok? Let's merge them in.

```bash
]$ git checkout master
]$ git merge feature-x
```

Now, let's look at our log:

```bash
]$ git log
```

*Notice how the commits made to the 'feature-x' branch are now part of the commit history for the master branch*

The basic log by itself is not that helpful when looking at branches, so let's add the --graph argument:

```bash
]$ git log --graph
```

Or, for more compressed view:

```bash
]$ git log --graph --pretty=oneline --abbrev-commit
```

The challenge with the default merge is you graphically lose track of what commits were part of the branch.

To retain this helpful information, use the following work-flow:

```bash
]$ git checkout -b feature-y
... make changes ...
]$ git add .
]$ git commit -m "[message]"
... switch back to master ...
]$ git checkout master
```

Now the big difference:

```bash
]$ git merge --no-ff feature-y
```

By adding '--no-ff', the git log will graphically keep the history of the branch in tact.

Give it a shot via:

```bash
]$ git log --graph
```
