Challenge - 5 Problems
Branch Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
Output of creating and switching to a new branch
What is the output of the command
git switch -c feature when run in a clean repository?Git
git switch -c featureAttempts:
2 left
💡 Hint
The command creates a new branch and switches to it in one step.
✗ Incorrect
The
git switch -c feature command creates a new branch named 'feature' and switches to it immediately, showing the message 'Switched to a new branch 'feature''.💻 Command Output
intermediate2:00remaining
Error when switching to an existing branch with -c
What happens if you run
git switch -c main when the branch 'main' already exists?Git
git switch -c mainAttempts:
2 left
💡 Hint
The -c option tries to create a new branch, so it fails if the branch exists.
✗ Incorrect
Using
-c with git switch tries to create a new branch. If the branch already exists, Git shows an error: 'fatal: A branch named 'main' already exists.'🔀 Workflow
advanced2:00remaining
Correct command to create and switch to a new branch in one step
Which command correctly creates and switches to a new branch named 'release' in one step?
Attempts:
2 left
💡 Hint
The
git switch command with -c creates and switches in one step.✗ Incorrect
The command
git switch -c release creates a new branch 'release' and switches to it immediately. Option A also works but uses the older checkout command. Option A has wrong option order. Option A is two steps, not one.❓ Troubleshoot
advanced2:00remaining
Troubleshooting error when creating and switching branch
You run
git switch -c feature but get the error: fatal: You have unstaged changes. What is the most likely cause?Attempts:
2 left
💡 Hint
Git prevents switching branches if unstaged changes would be lost.
✗ Incorrect
Git blocks switching branches if you have unstaged changes that would be overwritten. You need to commit, stash, or discard changes before switching.
✅ Best Practice
expert2:00remaining
Best practice for creating and switching branches in scripts
In an automated script, which command is best to create and switch to a new branch 'hotfix' only if it does not already exist, without causing errors?
Attempts:
2 left
💡 Hint
Suppress errors when switching to existing branch, then create if missing.
✗ Incorrect
Option D tries to switch to 'hotfix' branch, suppressing error output, and if it fails (branch missing), it creates and switches with
-c. This avoids script failure and handles both cases cleanly.