How do you create a new branch from an existing branch in Git?

How do you create a new branch from an existing branch in Git?

a) git checkout -b new-branch
b) git branch create new-branch
c) git switch --create new-branch
d) git merge --create new-branch

Answer:

a) git checkout -b new-branch

Explanation:

The git checkout -b new-branch command creates a new branch and immediately switches to it. This is a commonly used command when you want to start work on a new feature or task.

This command is equivalent to running git branch new-branch followed by git checkout new-branch in a single step.

Creating new branches is essential for isolating work on features, bug fixes, or experiments.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top