Blog

Switch Branches Without Losing Work in Git

You have made changes on the wrong Git branch. Maybe you forgot to create a feature branch or started working directly on dev or main. No commits yet, just local edits.

Don’t panic. You can fix this in seconds with git stash.

Step 1: Stash your local changes

git stash

Step 2: Checkout the correct branch

git checkout qa
git checkout -b feature/my-task

Step 3: Apply your changes

git stash pop

That’s it. You are now on the right branch with all your work.

Bonus tip: If you are not sure about whether you have stashed something, run git stash list. And remember, git stash is local, your changes won’t affect your teammates unless you commit & push.

🔗 Related Posts