Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Automatically stash+pop on checkout

Tags:

git

git-stash

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?

like image 368
guettli Avatar asked Jan 26 '18 08:01

guettli


People also ask

How do I get git stash pop?

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.

What is auto stash in git?

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.

Why is git stash pop used?

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.


1 Answers

GIT >= 2.27.0

Having changes not staged for commit:

git switch other_branch

and now we are on other_branch with those changes.

like image 183
suside Avatar answered Oct 18 '22 16:10

suside