1

I am behind of master of one commit. I know the commit only affects file A. I have a local change of file B. Even B will not be changed, git still won't pull but let me do stash or discard local changes. Is there any way to pull from master without committing or stashing or resetting file B.

Now I have to stash it and pop it back. I am not sure but I remember years ago I can just pull head with irrelevant local changes. Did I miss some settings?

7
  • 2
    Why don't you want to stash? That is what it is used for (among other things). Commented Jul 5, 2021 at 1:19
  • 1
    Does this answer your question? Git Pull While Ignoring Local Changes? Commented Jul 5, 2021 at 1:21
  • 1
    From memory, maybe you are allowed to merge if the files you have modified in your working tree are not affected by the merge.... but I wouldn't bet on it. Anyway, can you add the commands you are using and their output in the question? Commented Jul 5, 2021 at 1:22
  • It's true that in ancient versions of Git, git pull would sometimes work even with uncommitted changes. However, in ancient versions of Git, git pull would sometimes destroy uncommitted work. It's a tradeoff, you can have a 100% working Git that doesn't let you do this, or a buggy ancient Git that does but loses your files. :-) Commented Jul 5, 2021 at 12:43
  • More seriously, the "autostash" mode (rebase only) does work. I dislike it for the same reason I dislike git stash: it's overly fragile. If the rebase goes wrong, the stash doesn't get auto-unstashed (in at least some versions of Git, maybe all, I have not checked lately). The new autostash-with-merge also works, but I'd expect the same caveat (if the merge stops, you have to finish it manually, after which I imagine you have to unstash manually too). Commented Jul 5, 2021 at 12:44

1 Answer 1

3

You can git fetch with active changes but git pull needs to merge or rebase, and therefore needs a clean working tree.

There is shortcut though, git pull --rebase --autostash will automatically stash, pull, and apply the stash back. There are more details in this other question.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this does solve my problem. I wonder why the rebase is necessary since If I stash by myself I won't add rebase here. Well as I never commits, just pulls, I'm ok with this option.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.