# Why can't git pull --rebase work if there are modified files?

2 messages from 2008-12-30 to 2008-12-30. Participants: skillzero@gmail.com, Thomas Rast.
Thread: https://gitlist.dev/t/16930

## skillzero@gmail.com, 2008-12-30 21:40

Subject: Why can't git pull --rebase work if there are modified files?
Message-ID: <2729632a0812301340y735c3946weee55c9856d4e6a9@mail.gmail.com>
URL: https://gitlist.dev/e/2729632a0812301340y735c3946weee55c9856d4e6a9%40mail.gmail.com

```
If I have locally modified files and I try to 'git pull --rebase', it
fails because of the locally modified files. If I don't use the
--rebase option, it works (but generates a merge commit if I have
local commits). Why does rebasing require an unmodified checkout? It
seems like it should only stop if I something in the newly fetched
changes conflict with my local changes.

I almost always have modified files in my checkout for things I'm
working on. I also often have a commit or two that haven't been pushed
because I'm waiting until I get to a good point before pushing. If I
do 'git pull', I end up with a merge commit each time. That's why I
want to use --rebase, but for it to work, I have to git stash, then
rebase then git stash pop.

```

## Thomas Rast, 2008-12-30 23:09

Subject: Re: Why can't git pull --rebase work if there are modified files?
Message-ID: <200812310009.12052.trast@student.ethz.ch>
URL: https://gitlist.dev/e/200812310009.12052.trast%40student.ethz.ch
In-Reply-To: <2729632a0812301340y735c3946weee55c9856d4e6a9@mail.gmail.com>

```
skillzero@gmail.com wrote:
> If I have locally modified files and I try to 'git pull --rebase', it
> fails because of the locally modified files. If I don't use the
> --rebase option, it works (but generates a merge commit if I have
> local commits). Why does rebasing require an unmodified checkout? It
> seems like it should only stop if I something in the newly fetched
> changes conflict with my local changes.

First you need to be aware that 'git pull --rebase' is conceptually
the same as 'git fetch && git rebase upstream', where 'upstream' is
the remote branch tracked by your current branch.  (The canonical
choice is upstream=origin/foo for a branch foo.)  git-fetch is of no
further interest to the discussion, as it does not touch the working
tree in any way.

git-rebase is not concerned with "newly fetched changes".  It
*rewinds* your branch to the updated 'upstream' tip, and then
*rebuilds* your commits on top of that.  This involves a lot of
resetting and applying patches, which appears to be why it enforces a
clean working tree.

You can use git-stash (see the man page) to temporarily save away your
uncommitted changes, however.  Maybe you could even write a patch to
git-rebase that lets it automatically save and restore uncommitted
changes?

> I almost always have modified files in my checkout for things I'm
> working on. I also often have a commit or two that haven't been pushed
> because I'm waiting until I get to a good point before pushing. If I
> do 'git pull', I end up with a merge commit each time. That's why I
> want to use --rebase, but for it to work, I have to git stash, then
> rebase then git stash pop.

You could probably improve your workflow a lot by using topic
branches.  See the recently added gitworkflows manpage, also available
at

  http://www.kernel.org/pub/software/scm/git-core/docs/gitworkflows.html

or, e.g., Tv's excellent introduction to git called "Version Control
for Du^H^HDevelopers":

  http://eagain.net/blog/2008/08/11/ep-talk-videos.html

(Pretty much the second half is about branch workflows, topic branches
are explicitly introduced at ~44:15.)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch


```
