Halfway through a change, you need another branch. Git refuses to switch when it would overwrite your unsaved edit:
git switch main
error: Your local changes to the following files would be overwritten by checkout:
app.js
Please commit your changes or stash them before you switch branches.
AbortingCommitting half-done work would leave a broken commit. Instead, stash it: git shelves your changes and gives you back a clean folder.
git stash
Saved working directory and index state WIP on feature/faq: 472e6b8 Route the FAQ
git stash list ← what's on the shelf
stash@{0}: WIP on feature/faq: 472e6b8 Route the FAQNow you can switch away, do the other job, and come back. git stash pop puts the changes back and takes them off the shelf:
git stash pop
On branch feature/faq
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: app.js
Untracked files:
(use "git add <file>..." to include in what will be committed)
faq.html
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (9324ca9329eb8bb3593a49a3554bb9f61f812043)faq.html was never stashed. git stash takes only changes to files git tracks. A new, untracked file stays in your folder and follows you to the other branch, where a later git add could sweep it into the wrong commit. git stash -u takes untracked files too.
Objectives
- Fix the README typo on
main, without your unfinished search work. - Pick your work back up on
feature/search.