0
0
Gitdevops~20 mins

Switching branches with git switch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Git Switch Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
1:30remaining
Output of switching to an existing branch
What is the output when you run git switch feature-xyz if the branch feature-xyz exists and you have no uncommitted changes?
Aerror: pathspec 'feature-xyz' did not match any file(s) known to git
BSwitched to branch 'feature-xyz'
Cfatal: You have uncommitted changes. Please commit or stash them first.
DAlready on 'feature-xyz'
Attempts:
2 left
💡 Hint
Think about what git says when you successfully switch branches.
💻 Command Output
intermediate
1:30remaining
Error when switching to a non-existent branch
What error message appears when you run git switch non-existent-branch and the branch does not exist?
Aerror: pathspec 'non-existent-branch' did not match any file(s) known to git
Bfatal: You have uncommitted changes. Please commit or stash them first.
CSwitched to branch 'non-existent-branch'
DAlready on 'non-existent-branch'
Attempts:
2 left
💡 Hint
Git tells you when the branch name is unknown.
🔀 Workflow
advanced
1:30remaining
Creating and switching to a new branch in one command
Which command correctly creates a new branch named hotfix and switches to it immediately?
Agit switch hotfix -b
Bgit switch --new hotfix
Cgit switch -c hotfix
Dgit switch create hotfix
Attempts:
2 left
💡 Hint
The option to create a branch with git switch is a single letter.
Troubleshoot
advanced
1:30remaining
Error when switching branches with uncommitted changes
What error message will you get if you try to run git switch develop while having uncommitted changes that conflict with the develop branch?
Aerror: Your local changes to the following files would be overwritten by checkout:
Bfatal: You have uncommitted changes. Please commit or stash them first.
CSwitched to branch 'develop'
DAlready on 'develop'
Attempts:
2 left
💡 Hint
Git warns about overwriting local changes when switching branches.
🧠 Conceptual
expert
2:00remaining
Behavior of git switch with detached HEAD
What happens when you run git switch --detach without specifying a branch or commit?
AGit switches to the default branch (usually main or master).
BGit throws an error because a commit or branch must be specified.
CGit creates a new branch named 'detach' and switches to it.
DGit detaches HEAD at the current commit, allowing you to explore without moving any branch.
Attempts:
2 left
💡 Hint
Think about what 'detached HEAD' means in Git.