Subject: Re: skip-worktree autostash on pull

From: Junio C Hamano <[email-masked]>
Date: Thu, 14 Sep 2023 14:53:40 -0700

"brian m. carlson" <[email-masked]> writes:

> Your particular case is one of many reasons we suggest this approach.
> There is in fact an --autostash argument in git pull, as well as git
> rebase, both of which work as you might expect, but in general they
> still won't work properly with --skip-worktree and given the FAQ entry
> above, we wouldn't add support for that in the option.

As you mentioned, "--autostash" will move away the local change
while your otherwise clean working tree needs to be updated from the
upstream via "git pull" (or "git pull --rebase").  So the only thing
the user may want to be careful would be "git commit -a" (and "git
add -u"), I would think.  A pre-commit hook should be able to stop
you from committing with local changes to these selected paths you
want to keep following the upstream _with_ local changes (i.e. run
"diff --cached --name-only HEAD" and exit with non-zero when one of
these paths appear in its output).  Upon seeing such a failure, you
can "git stash" the changes, then "git commit" again.  And you do
not need to abuse assume-unchanged or skip-worktree for doing that.