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 9 of 100

What is a branch in Git, and how do you create one?

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

In Git, a branch is a separate line of development that allows you to work on new features or changes to your codebase without affecting the main codebase. Branches can be used to experiment with new ideas, fix bugs, or make major changes to the codebase without disrupting the main development workflow.

To create a new branch in Git, you can use the git branch command followed by the name of the new branch. Here’s an example of how to create a new branch:

    # Create a new branch called "new-feature"
    git branch new-feature

After running this command, you will have a new branch called "new-feature". However, you will still be working on the original branch. To switch to the new branch, you can use the git checkout command:

    # Switch to the new "new-feature" branch
    git checkout new-feature

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

Alternatively, you can create a new branch and switch to it in one step by using the git checkout command with the -b option:

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

This command will create a new branch called "new-feature" and switch to it in one step.

Once you’ve created a new branch, you can make changes to the files in your repository as usual. Any changes you make on the new branch will be isolated from the main codebase until you merge the changes back into the main branch.

In summary, branches are a powerful feature of Git that allow you to experiment with new features or changes to your codebase without affecting the main codebase. You can create a new branch using the git branch command and switch to it using the git checkout command. Alternatively, you can create and switch to a new branch in one step using the git checkout -b 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