Branches in a Nutshell
Branching means you diverge from the main line of development and continue to do work without messing with that main line.
Head
We'll often come across the term HEAD in Git. HEAD is simply a pointer that refers to the current "location" in our repository. It points to a particular branch reference.So far, HEAD always points to the latest commit we made on the master branch, but soon we'll see that we can move around and HEAD will change!
Branches in a Nutshell
$ git branch
git branch is used to view the existing branches. The default branch in every git repo is master,though we can configure this.
Look for the * which indicates the branch we are currently on.
Creating a Branch
$ git branch "branch-name"
git branch "branch-name" to make a new branch based upon the current HEAD. This just creates the branch. It does not switch us to that branch (the HEAD stays the same)
Switching to a Branch
$ git checkout "branch-name"
$ git checkout -b "branch-name" => creats a branch and swithch to it.
When we make a new commit, it exists only on new branch, not on master!. we used git checkout "branch-name" to switch branches.
Viewing More Info
Use the -v flag with git branch to view more information about each branch.
$ git branch -v
Deleting a Branch
$ git branch -d "branch-name"