Cannot pull with rebase: You have unstaged changes. Please commit or stash them. Git stash command is kind of commit stored changes to temporary space and clean working copy. Then your working copy will be reverted to HEAD.It is a good place to store uncommitted changes.
If you type git rebase --continue. you realize the error is because of a merge conflict that git cannot resolve by itself, and needs your help. To see what files have conflicts, type git status. Resolve the merge conflicts in your favorite editor/IDE (hint: this should start with i and end with ntelliJ)
Git pull rebase is a method of combining your local unpublished changes with the latest published changes on your remote. Let's say you have a local copy of your project's main branch with unpublished changes, and that branch is one commit behind the origin/main branch.
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.
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
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:
git stash
git stash apply stash@{0}
or the simpler git stash pop
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With