Creating and Using Branches in Git

Here are some basic work flows for working with the Git repository, especially the power of the branching features that Git offers.

To create a new branch and switch to that branch use:
$git checkout -b my_branch
Any changes that are done now will be reflected in the new branch and not the master.

To see what branch you are working on use:
$git branch
You should see an * beside the name of the branch that is current

To go back to our master branch use:
$git checkout master
Now any changes that are made will be reflected in the master branch but are not automatically populated to your new branch.

To merge our new branch into our master branch use:
$git merge my_branch
We do not need to specify where we are going to do the merge because we are already in the master branch.

To delete our new branch now that we have done a merge use:
$git branch -d my_branch

Another option for merging our branch into the master branch is the following:
$git checkout my_branch
$git rebase master
Fix any conflicts and do:
$git add
$git rebase --continue
$git checkout master
$git merge my_branch
This will make the history much cleaner.