What does the command git checkout -b branchname do?

What does the command git checkout -b branchname do?

a) Creates and switches to a new branch
b) Merges a branch
c) Deletes a branch
d) Checks out the latest commit on the main branch

Answer:

a) Creates and switches to a new branch

Explanation:

The git checkout -b branchname command creates a new branch with the specified name and immediately switches to it. This is a shortcut for creating a branch with git branch branchname followed by git checkout branchname.

For example, git checkout -b feature-branch creates and switches to a branch named feature-branch.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top