Practical Guide to GIT branch


Git branches are an essential part of the Git version control system. They allow you to work on different features or versions of your project simultaneously, without affecting the main codebase. Here are some examples of how to explore and manage Git branches:

List all branches:

To list all the branches in your Git repository, you can use the git branch command:

$ git branch

This will show you a list of all branches in the repository, with an asterisk (*) next to the currently checked-out branch.

Switch to a different branch:

To switch to a different branch, you can use the git checkout command followed by the name of the branch you want to switch to:

$ git checkout <branch-name>

For example, to switch to a branch named feature-branch, you can use:

$ git checkout feature-branch
$ git checkout -b feature-branch // if branch does not exists then creates feature-branch and switches to that

Create a new branch:

To create a new branch, you can use the git branch command followed by the name of the new branch:

$ git branch <new-branch-name>

For example, to create a new branch named new-feature, you can use:

$ git branch new-feature

Delete a branch:

To delete a branch, you can use the git branch command with the -d option followed by the name of the branch you want to delete:

$ git branch -d <branch-name>

For example, to delete a branch named old-feature, you can use:

$ git branch -d old-feature

Merge a branch:

To merge a branch into the current branch, you can use the git merge command followed by the name of the branch you want to merge:

$ git merge <branch-name>

For example, to merge a branch named feature-branch into the current branch, you can use:

$ git merge feature-branch

Show the commit history of a branch:

To show the commit history of a branch, you can use the git log command followed by the name of the branch:

$ git log <branch-name>

For example, to show the commit history of a branch named feature-branch, you can use:

$ git log feature-branch

These are just a few examples of how to explore and manage Git branches. There are many other Git commands and options that can help you work with branches more effectively