Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What git command creates a new branch and switches to it immediately?
The command git switch -c <branch-name> creates a new branch and switches to it in one step.
Click to reveal answer
beginner
What does the -c option do in git switch -c?
The -c option stands for 'create'. It tells git to create a new branch before switching to it.
Click to reveal answer
beginner
How would you create and switch to a branch named feature1?
Use the command git switch -c feature1. This creates the branch feature1 and switches to it.
Click to reveal answer
intermediate
What is the difference between git checkout -b and git switch -c?
git checkout -b also creates and switches to a new branch, but git switch -c is a newer, clearer command introduced to separate switching branches from other checkout tasks.
Click to reveal answer
beginner
Can you switch to an existing branch using git switch?
Yes, simply use git switch <branch-name> without -c to switch to an existing branch.
Click to reveal answer
Which command creates and switches to a new branch named 'dev' in one step?
Agit switch dev
Bgit branch dev
Cgit switch -c dev
Dgit checkout dev
✗ Incorrect
git switch -c dev creates the new branch 'dev' and switches to it immediately.
What does the command git switch -c feature do?
ACreates a new branch named 'feature' and switches to it
BDeletes the branch named 'feature'
CSwitches to an existing branch named 'feature'
DLists all branches
✗ Incorrect
The -c option creates a new branch before switching to it.
Which command is the newer, clearer way to create and switch branches in git?
Agit checkout -b
Bgit switch -c
Cgit branch -c
Dgit create -s
✗ Incorrect
git switch -c is the newer command designed for creating and switching branches.
How do you switch to an existing branch named 'main' using git switch?
Agit switch main
Bgit switch -c main
Cgit checkout -b main
Dgit branch main
✗ Incorrect
git switch main switches to the existing branch 'main'.
What happens if you run git switch -c with a branch name that already exists?
AGit deletes the existing branch and creates a new one
BGit creates a new branch with the same name
CGit switches to the existing branch
DGit shows an error that the branch already exists
✗ Incorrect
Git will show an error because the branch name already exists and cannot be created again.
Explain how to create a new branch and switch to it in one step using git.
Think about the command that combines creation and switching.
You got /3 concepts.
Describe the difference between git checkout -b and git switch -c.
Focus on the purpose and clarity of the commands.
You got /3 concepts.
Practice
(1/5)
1. What does the command git switch -c feature do?
easy
A. Lists all branches including 'feature'
B. Creates a new branch named 'feature' and switches to it
C. Switches to the existing branch named 'feature' without creating it
D. Deletes the branch named 'feature'
Solution
Step 1: Understand the git switch -c command
The -c option means "create" a new branch and switch to it immediately.
Step 2: Apply to the branch name 'feature'
The command creates a new branch called 'feature' and switches the working directory to it.
Final Answer:
Creates a new branch named 'feature' and switches to it -> Option B
Quick Check:
git switch -c = create and switch [OK]
Hint: Remember: -c means create and switch in one step [OK]
Common Mistakes:
Thinking it only switches without creating
Confusing with branch deletion commands
Assuming it lists branches
2. Which of the following is the correct git switch syntax to create and switch to a new branch named dev?
easy
A. git switch -c dev
B. git switch dev -c
C. git checkout -b dev
D. git branch -c dev
Solution
Step 1: Recall the correct order of options in git switch
The option -c must come before the branch name to create and switch.
Step 2: Check each option
git switch -c dev is the correct syntax. git switch dev -c has wrong order. git checkout -b dev uses checkout instead of switch. git branch -c dev is invalid syntax.
Final Answer:
git switch -c dev -> Option A
Quick Check:
Correct syntax = git switch -c branch [OK]
Hint: Option -c always comes before branch name in git switch [OK]
Common Mistakes:
Placing -c after branch name
Confusing git switch with git branch
Using git branch -c which is invalid
3. What will be the output of the following commands?
The first command creates a new branch named 'test-branch' and switches to it.
Step 2: Show current branch
The second command prints the name of the current branch, which is now 'test-branch'.
Final Answer:
test-branch -> Option D
Quick Check:
Current branch after switch -c = new branch name [OK]
Hint: After switch -c, current branch is the new branch [OK]
Common Mistakes:
Assuming it stays on main branch
Expecting no output from show-current
Thinking it causes an error
4. You run git switch -c featureX but get an error: fatal: A branch named 'featureX' already exists. What should you do to switch to that branch?
medium
A. Run git switch featureX
B. Run git switch -c featureX again
C. Run git branch featureX
D. Run git checkout -b featureX
Solution
Step 1: Understand the error
The error means the branch 'featureX' already exists, so you cannot create it again.
Step 2: Switch to existing branch
Use git switch featureX without -c to switch to the existing branch.
Final Answer:
Run git switch featureX -> Option A
Quick Check:
Use switch without -c to switch existing branch [OK]
Hint: Use git switch without -c to switch existing branch [OK]
Common Mistakes:
Trying to create branch again with -c
Using git branch without switching
Using checkout -b which creates new branch
5. You want to create a new branch named release-1.0 and immediately start working on it. Which command correctly does this and also sets the upstream to origin/release-1.0 in one step?
hard
A. git checkout -b release-1.0 origin/release-1.0
B. git branch release-1.0 && git switch release-1.0
C. git switch -c release-1.0 --track origin/release-1.0
D. git switch release-1.0 -c --set-upstream origin/release-1.0
Solution
Step 1: Understand creating and switching with upstream
The git switch -c command can create and switch to a branch. The --track option sets the upstream branch.
Step 2: Analyze options
git switch -c release-1.0 --track origin/release-1.0 creates the branch, switches to it, and sets upstream in one step. git branch release-1.0 && git switch release-1.0 requires two commands. git checkout -b release-1.0 origin/release-1.0 creates and switches from the remote commit and sets upstream automatically. git switch release-1.0 -c --set-upstream origin/release-1.0 has wrong option order and syntax.
Final Answer:
git switch -c release-1.0 --track origin/release-1.0 -> Option C
Quick Check:
Use switch -c with --track to create, switch, and set upstream [OK]
Hint: Use --track with switch -c to set upstream in one step [OK]