Git Branching

Git branches are a powerful feature of Git that allow developers to work on different versions of their codebase simultaneously. Branches make it easy to work on new features or bug fixes without affecting the main codebase until the work is complete.

Creating git Branches

Use the following command to create a new branch:

git branch <branch-name>

Use the following command to list all branches:

git branch

Switching git Branches

Use the following command to switch to an existing branch:

git checkout <branch-name>

You can also use git switch instead of git checkout to create and switch to new branches.

Use the following command to create a new branch and switch to it:

git switch -c <branch-name>

Use the following command to switch to an existing branch:

git switch <branch-name>

Merging Branches and Handling Conflicts