How to create a new Git branch?

To create a new Git branch, you can follow these steps:

  1. Switch to the branch where you want to create the new branch. For example, if you want to create the new branch from the "main" branch, run:

    git checkout main
  2. Use the git branch command with the name of the new branch to create it. Replace <branch-name> with the desired name for the new branch. For example, to create a branch called "feature-branch," run:

    git branch feature-branch
  3. Switch to the newly created branch using the git checkout command. For example:

    git checkout feature-branch
  4. Alternatively, you can combine steps 2 and 3 by using the -b flag with the git checkout command. This creates the new branch and switches to it in one step. For example, to create and switch to a branch called "feature-branch" all at once, run:

    git checkout -b feature-branch

These steps will create a new branch in your Git repository. You can then start working on the new branch and make commits specific to that branch.