My Profile Photo

Sheogorath's Blog

Autostash

Today I learned that I can permanently enable the autostash feature in git. Autostash a parameter for git rebase, git merge or git pull, where git will automatically stash your local changes und unstash them after it finished the action. Usually you would use an option like git pull --autostash to instruct git to do this, however when using git config --global rebase.autostash true, git will be setup to simply automatically assume --autostash for all rebase actions without requiring any further specification. Same works for merges by specifying git config --global merge.autostash true.

I came across this when I faced the typical error message when one tries to rebase changes without a clean working directory. Usually I would just manually specify --autostash as part of the command, but why not find a more sustainable solution? And here I went and found one!

$ git pull                            
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.