Cannot pull with rebase
Solution 1
You can use the Python port of git-up: https://github.com/msiemens/PyGitUp
pip install git-up
Solution 2
git-up is probably the more sophisticated way to solve this issue.
Otherwise, you need to stash, rebase and stash pop.
The "more modern way" will be available in git 1.8.5 (or 1.9, Q4 2013).
As I mention in "Git - How to edit old (not previous) commit with some of the unstaged changes from current index (current state)?":
"
git rebase
" learned "--[no-]autostash
" option to save local changes instead of refusing to run (to which people's normal response was to stash them and re-run).
Since Git 2.9 (June 2016), you now have (as commented by artofwarfare):
git pull --rebase --autostash
Solution 3
You can't really "rebase" your uncommitted changes since git does not know about them yet. You should stash your local changes before you run git pull --rebase
then apply them back.
Solution 4
I answer a little late but maybe that can be useful for someone.
If you are just looking for a one-liner to execute stash / pull rebase / stash pop
, you can create an alias.
git config --global alias.spr '!f(){ git stash && git pull --rebase && git stash pop; };f'
This creates an alias named spr
that does the three operations and allows you to quickly pull --rebase
while you have unstaged changes.
git spr
guettli
http://thomas-guettler.de/ Working out loud: https://github.com/guettli/wol
Updated on July 23, 2022Comments
-
guettli almost 2 years
I get this message:
Cannot pull with rebase: You have unstaged changes. Please commit or stash them.
Yes, I have changes which are not committed. I searched a way to rebase my uncommitted changes on top of the new code which I would get from a pull.
I found this: https://github.com/aanand/git-up
I want to know if this is still the way to go, or if there are more modern ways to go.
I use git version 1.8.1
-
guettli over 10 yearsI know that this is possible, but a one-liner would be nice.
-
eoconnell over 10 yearsYou could always write a bash script that turns those three steps into a one-liner.
-
guettli over 9 yearsJust for the records: Since you loose history information if you use rebase, we decided to use "merge" in our company.
-
jww about 8 years"You can't really "rebase" your uncommitted changes since git does not know about them yet..." - git may not know about them, but the damn tool refuses to run nearly every command or even switch branches....
-
eoconnell almost 8 yearsIt's there as a safety precaution. Git doesn't want you to lose your changes. As VonC mentions, you can set the --autostash flag for one-offs or set rebase.autostash=true in your git config to apply it globally.
-
ArtOfWarfare over 6 yearsJust do
git pull --rebase --autostash
. Seems to have done exactly what I wanted. -
VonC over 6 years@ArtOfWarfare Actually these days (I.e.4 year after this old answer), I prefer a simple
git pull
, because ofgit config pull.rebase true; git config rebase.autoStash true
stackoverflow.com/a/30209750/6309: -
ArtOfWarfare over 6 yearsI'm writing a script which I expect multiple people at my company will be using. I don't want it to only work if they have all that configured in
git
(and I don't want to have the script change or validate their configuration.) I want it to just work, and the command in my first comment seems to do so. -
VonC over 6 years@ArtOfWarfare I agree, and have included that newer command in the answer for more visibility. But your people at your company must have Git 2.9+ (June 2016).