Home > database >  Where does this rebase come from?
Where does this rebase come from?

Time:09-21

I recently created a new branch locally, published it to remote and it received an update from a colleague. While I do have changes in my repository, none of them are on files that were modified. I therefore expected that a git pull would work as implied by the message from git status:

$ git status
On branch XXX
Your branch is behind 'origin/XXX' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   ...

However pulling results in an error message implying that there is a rebase in progress:

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

I don't know where this might have come from as I never consciously did a rebase. Also, strangely:

$ git rebase --continue
fatal: No rebase in progress?

I can pull when stashing my changes and popping them afterwards without a problem, and am aware of the autostash option, but I would like to understand what is going on here.

Where did the rebase come from? Why do git pull and git rebase appear to disagree whether there is a rebase? How can I clean up this mess?

CodePudding user response:

Where did the rebase come from?

As @coyotte508 pointed out, you have likely configured git pull to do a rebase instead of a merge by setting the pull.rebase option in your Git config file (either globally or in the current repo).

Why do git pull and git rebase appear to disagree whether there is a rebase?

They don't. git pull simply refused to do the rebase because you have uncommitted changes in your working directory. By the time git pull exits, there's no rebase in progress.

How can I clean up this mess?

You can either commit or stash your changes prior to doing git pull (the rebase.autostash option that you mentioned will do the latter for you automatically). Alternatively, you could set pull.rebase to false and have git pull do a regular merge, but I wouldn't recommend it.

CodePudding user response:

You probably have rebase automatically enabled when pulling. Try

git config pull.rebase
git config --global pull.rebase

See if either is true. If that's the case, you can do:

git config pull.rebase false
git config --global pull.rebase false

(or use --unset)

  • Related