What is the command to switch to another branch in Git?

What is the command to switch to another branch in Git?

a) git checkout branch-name
b) git switch branch-name
c) Both a and b
d) git change branch-name

Answer:

c) Both a and b

Explanation:

In Git, you can switch to another branch using either git checkout branch-name or git switch branch-name. The checkout command was traditionally used for this purpose, but newer versions of Git introduced the switch command for clarity.

Both commands achieve the same result, but switch is more intuitive for switching branches, whereas checkout can be used for other operations like switching to a specific commit.

Switching branches allows you to move between different streams of development and work on multiple features without losing progress on any of them.

Reference:

Top 100 Git and GitHub MCQ Questions and Answers

Scroll to Top