Reputation: 31567
Is there any way to switch from one feature
branch to another, when the changes in the current feature
branch are not yet ready to be committed?
I often find myself in a situation where I'm out of ideas when implementing a new feature or fixing a bug and I need to switch gears and work on something else. However, I do not know how to switch branches without losing all the uncommitted work I did up until that point.
Upvotes: 5
Views: 968
Reputation: 387547
You basically have two options:
git stash
to save all the changes and keep them somewhere save. Afterwards, you will end up with a clean working directory so you can switch branches. Then, when you come back, you can use git stash apply
to apply the changes from the last stash, so you’re back at where you left off.git commit --amend
to amend that commit and “make it better”, or you can use git reset --soft HEAD~1
to remove that commit (without losing the changes you did).Upvotes: 6