I know how to solve this:
user@host$ git pull
error: Your local changes to the following files would be overwritten by merge:
Please, commit your changes or stash them before you can merge.
git stash; git pull; git stash pop
For Git 2.6+ (released 28 Sept 2015)
git config setting which would be of interest is:
When set to true, automatically create a temporary stash before the operation begins, and apply it after the operation ends.
This means that you can run rebase on a dirty worktree.
However, use with care: the final stash application after a successful rebase might result in non-trivial conflicts. Defaults to false.
combine that with:
When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.
git config pull.rebase true git config rebase.autoStash true
That would be enough for a simple
git pull to work even in a dirty tree.
No alias needed in that case.
pull: allow dirty tree when
rebase learned to stash changes when it encounters a dirty work tree, but
git pull --rebasedoes not.
Only verify if the working tree is dirty when
rebase.autostashis not enabled.
Note: if you want to pull without autostash (even though
rebase.autoStash true is set), you have since git 2.9 (June 2016):
pull --rebase --no-autostash
See commit 450dd1d, commit 1662297, commit 44a59ff, commit 5c82bcd, commit 6ddc97c, commit eff960b, commit efa195d (02 Apr 2016), and commit f66398e, commit c48d73b (21 Mar 2016) by Mehul Jain (
(Merged by Junio C Hamano --
gitster -- in commit 7c137bb, 13 Apr 2016)
Commit f66398e in particular includes:
pull --rebase: add
rebase.autoStashconfiguration variable is set, there is no way to override it for "
git pull --rebase" from the command line.
git pull --rebase" the
--[no-]autostashcommand line flag which overrides the current value of
rebase.autoStash, if set. As "
git rebase" understands the
--[no-]autostashoption, it's just a matter of passing the option to underlying "
git rebase" when "
git pull --rebase" is called.