Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Git commands: Git Switch: Changing the Current Branch Safely

Create a disposable repository with at least two divergent local branches. Make one branch current, introduce a controlled local modification, and attempt to switch to the other branch. Record whether Git permits or rejects the switch and why. Then repeat with a non-conflicting local modification, use `git switch -` to return to the previous branch, create a new branch with `git switch -c` from an explicit start point, and verify every resulting branch tip with `git rev-parse --verify <name>^{commit}`. In a separate disposable repository, demonstrate the difference between `--discard-changes` and `--merge`; if `--merge` produces a conflict, inspect the index state rather than hiding it. Do not use detached HEAD in this exercise; that belongs to the next lesson. Success requires evidence of the state transition: current branch before and after, target branch tip object IDs, working-tree/index status, and the exact reason a switch was accepted or refused. Destructive flags must be demonstrated only in disposable repositories.

Intermediate ~6 min read

Challenge 1

Complete the Git command to change the checked-out branch.

bash Your answer
git  -

Press Ctrl⌘Enter to check your answer

Challenge 2

Complete the Git command to change the checked-out branch.

bash Your answer
git  -c

Press Ctrl⌘Enter to check your answer

Challenge 3

Complete the Git command to change the checked-out branch.

bash Your answer
git  other

Press Ctrl⌘Enter to check your answer

Challenge 4

Complete the Git command to change the checked-out branch.

bash Your answer
git  -c fixup HEAD~1

Press Ctrl⌘Enter to check your answer