06 / 09

How do you create and switch to a new branch?

javascript
Difficulty: 2/10
Topics: branch creation, branch switching, workflow

Scenario Questions

0-2 years experience
  1. 1

    You need to start working on a bug fix. Walk me through the exact git commands you would use to create a new branch for this fix and switch to it.

  2. 2

    If you run git checkout -b feature/login and then realize you made a typo in the branch name, how would you correct it without losing your work?

2-5 years experience
  1. 1

    While implementing a new feature, you created a branch and later discovered that the base branch had new commits. How would you update your branch, and what considerations affect whether you rebase or merge?

  2. 2

    During a code review, a teammate points out that your branch name doesn't follow the team's naming convention. How would you rename the branch locally and on the remote without disrupting others?

5-8 years experience
  1. 1

    Our repository has hundreds of active feature branches. Describe how you would manage branch creation and switching to minimize merge conflicts and keep CI pipelines efficient.

  2. 2

    We need to enforce a policy where only certain branches can be pushed to production. How would you incorporate branch creation and switching into a workflow that integrates protected branches and automated checks?

8+ years experience
  1. 1

    Our organization is moving from a trunk‑based development model to a long‑living release‑branch strategy across multiple teams. Explain how you would redesign the branching and switching process, tooling, and documentation to support this migration at scale.

  2. 2

    When scaling a monorepo with thousands of developers, what branching conventions and automation would you put in place to ensure that creating and switching branches remains fast and doesn't cause repository bloat?

Follow-up Questions

  • What happens if you try to switch to a branch that has uncommitted changes?
  • How would you rename a local branch and update the remote reference?
  • Can you explain the difference between `git checkout` and `git switch` for creating and switching branches?