git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: skip-worktree autostash on pull

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Sep 14, 2023, 21:37 UTC
Message-ID
<ZQN9Azt/K28WLfqH@tapette.crustytoothpaste.net>
In-Reply-To
<AB6A85F5-3E76-4462-931E-AD76E0066C37@mpbell.io>
On 2023-09-14 at 09:54:30, Blake Campbell wrote:
Show 6 quoted lines
> Hi all - I use update-index --skip-worktree on some config files that
> I change locally and don’t want to commit, but every time I pull from
> the remote I have to go through a process of no-skip-worktree, stash,
> pull, stash pop, then skip-worktree again, which is all a bit tedious!
> Ideally some switch like --autostash for git pull would be really
> useful. Does anyone know if something like that exists? 

The Git FAQ[0] outlines that, as you've noticed, skip-worktree doesn't work for ignoring changes to tracked files:

  Git doesn’t provide a way to do this. The reason is that if Git needs
  to overwrite this file, such as during a checkout, it doesn’t know
  whether the changes to the file are precious and should be kept, or
  whether they are irrelevant and can safely be destroyed. Therefore, it
  has to take the safe route and always preserve them.
  It’s tempting to try to use certain features of git update-index,
  namely the assume-unchanged and skip-worktree bits, but these don’t
  work properly for this purpose and shouldn’t be used this way.

If you take the advice in the FAQ, then the config files won't be tracked and you won't have this problem:

  If your goal is to modify a configuration file, it can often be
  helpful to have a file checked into the repository which is a template
  or set of defaults which can then be copied alongside and modified as
  appropriate. This second, modified file is usually ignored to prevent
  accidentally committing it.

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.

[0] https://git-scm.com/docs/gitfaq#ignore-tracked-files
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
Previous: Blake CampbellNext: Junio C Hamano
Message 2 of 3 in “skip-worktree autostash on pull”
  1. Blake CampbellSep 14, 2023
  2. brian m. carlsonSep 14, 2023
  3. Junio C HamanoSep 14, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.