Error: Cannot pull with rebase: You have unstaged changes
If you want to keep your working changes while performing a rebase, you can use --autostash
. From the documentation:
Before starting rebase, stash local modifications away (see git-stash[1]) if needed, and apply the stash when done.
For example:
git pull --rebase --autostash
First start with a
git status
See if you have any pending changes. To discard them, run
note that you will lose your changes by running this
git reset --hard
Do git status
, this will show you what files have changed. Since you stated that you don't want to keep the changes you can do git checkout -- <file name>
or git reset --hard
to get rid of the changes.
For the most part, git will tell you what to do about changes. For example, your error message said to git stash
your changes. This would be if you wanted to keep them. After pulling, you would then do git stash pop
and your changes would be reapplied.
git status
also has how to get rid of changes depending on if the file is staged for commit or not.
Pulling with rebase is a good practice in general.
However you cannot do that if your index is not clean, i.e. you have made changes that have not been committed.
You can do this to work around, assuming you want to keep your changes:
- stash your changes with:
git stash
- pull from master with rebase
- reapply the changes you stashed in (1) with:
git stash apply stash@{0}
or the simplergit stash pop