WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 10 of 100

How do you switch between branches in Git?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

In Git, switching between branches is a common operation when working with multiple lines of development in a codebase. To switch between branches, you can use the git checkout command.

Here’s an example of how to switch to an existing branch:

    # Switch to an existing branch called "new-feature"
    git checkout new-feature

After running this command, you will be switched to the "new-feature" branch. Any changes you make to files in your repository will be made on this branch.

If you want to create a new branch and switch to it in one step, you can use the -b option with the git checkout command:

    # Create and switch to a new branch called "new-feature"
    git checkout -b new-feature

After running this command, you will be switched to the new "new-feature" branch, and any changes you make to files in your repository will be made on this branch.

To list all branches in your repository, you can use the git branch command:

    # List all branches in the repository
    git branch

This command will show a list of all branches in your repository, with the current branch highlighted with an asterisk (*).

In summary, switching between branches in Git is a simple and common operation when working with multiple lines of development. To switch to an existing branch, use the git checkout command followed by the name of the branch. To create and switch to a new branch in one step, use the -b option with the git checkout command. You can list all branches in your repository using the git branch command.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics