Git & GitHub Interview Question #23
How do you create and switch branches in modern Git?
Git Fundamentals, Repository, Working Tree, Staging, Commits & Branch Basics Junior Beginner
Quick Interview Answer
git switch can be used to move between branches, and git switch -c creates a new branch and switches to it. Older workflows commonly use git checkout for both file and branch operations.
Detailed Explanation
git switch can be used to move between branches, and git switch -c creates a new branch and switches to it. Older workflows commonly use git checkout for both file and branch operations.
Using git switch makes branch intent explicit and is often easier for beginners to understand, although git checkout remains widely encountered in existing documentation and workflows.
Code Example
git switch -c feature/git-interview
# Later
git switch main