Believing file.txt is tracked on main after switch
4. You try to run git switch feature but get the error: error: Your local changes to the following files would be overwritten by checkout: What should you do to fix this and switch branches safely?
medium
A. Use git switch -f feature to force switch ignoring changes.
B. Commit or stash your changes before switching branches.
C. Delete the files manually and try again.
D. Run git reset --hard without saving changes.
Solution
Step 1: Understand the error meaning
The error means you have local changes that would be lost if you switch branches.
Step 2: Safely save changes before switching
You should either commit your changes or stash them to save work before switching branches.
Final Answer:
Commit or stash your changes before switching branches. -> Option B
Quick Check:
Save changes before switching to avoid overwrite errors [OK]
Hint: Commit or stash changes before switching branches [OK]
Common Mistakes:
Forcing switch and losing work
Deleting files manually causing data loss
Resetting hard without backup
Ignoring the error and expecting switch to work
5. You want to create a new branch release from main, switch to it, and keep your current uncommitted changes safe. Which sequence of commands achieves this correctly?
hard
A. git switch -c release git stash git stash pop
B. git commit -m 'temp' git switch -c release
C. git switch release git stash git switch -c release
D. git stash git switch -c release git stash pop
Solution
Step 1: Save uncommitted changes safely
Use git stash to save current uncommitted changes temporarily.
Step 2: Create and switch to new branch
Run git switch -c release to create and switch to the 'release' branch.
Step 3: Restore saved changes
Use git stash pop to apply the saved changes to the new branch.
Final Answer:
git stash git switch -c release git stash pop -> Option D
Quick Check:
Stash changes, switch branch, then pop stash [OK]
Hint: Stash changes before switching, then pop after [OK]
Common Mistakes:
Switching branch before stashing causing errors
Committing temporary changes unnecessarily
Forgetting to pop stash after switching
Trying to switch without saving changes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.