If I do git checkout my-super-branch
git tells me:
error: Your local changes to the following files would be overwritten by checkout:
somedir/somefile.py
Please, commit your changes or stash them before you can switch branches.
Aborting
Is there a simple way to tell git to do stash+pop automatically?
Retrieving stashed changes You can reapply stashed changes with the commands git stash apply and git stash pop . Both commands reapply the changes stashed in the latest stash (that is, stash@{0} ). A stash reapplies the changes while pop removes the changes from the stash and reapplies them to the working copy.
Since Git version 2.6, git rebase now has a feature/option called autostash. From git rebase docs: --autostash. --no-autostash. Automatically create a temporary stash before the operation begins, and apply it after the operation ends.
Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
GIT >= 2.27.0
Having changes not staged for commit:
git switch other_branch
and now we are on other_branch
with those changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With