Published March 07, 2018 by

Git - Branching

Using branches
The Git branches are simply pointers to a specific commit. There is no storage/memory overhead with making multiple branches in your git repository. It is easier to logically divide up your work into smaller branches than heavy branches. For example, you want to add a new feature or fix a bug the branches are the best use for the tasks.

Create New Branch

Using git branch command we can create a new branch.

# git branch development

Switch to Branches

Using git checkout command we can switch to another branch.

# git checkout development

Create and Switch Branch

To create branch and switch. We can do the same with a single command. This will create a new branch and switch immediately.

# git checkout -b development

List Branches

Using git branch command to list currently available branches. The * shows the active branch

git branch

* development

  master
  subhash

Fetch Remote Branches

Another developer has created a new branch and pushed to the remote git repository. Now you need to fetch that branch in your development environment. You can fetch all branches available on remote git repository using the command:

# git fetch -- all

After that switch to that branch using git checkout.

# git checkout branch_name


Previous: Push Code                                                      Next: Delete Branches