{"thread":{"id":"60231","subject":"skip-worktree autostash on pull","startedAt":"2023-09-14T10:04:25Z","lastAt":"2023-09-14T21:53:47Z","messageCount":3,"participants":["Blake Campbell","brian m. carlson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"481839","messageId":"AB6A85F5-3E76-4462-931E-AD76E0066C37@mpbell.io","threadId":"60231","inReplyTo":null,"subject":"skip-worktree autostash on pull","fromName":"Blake Campbell","fromEmail":"bc@mpbell.io","sentAt":"2023-09-14T09:54:30Z","receivedAt":"2023-09-14T10:04:25Z","isPatch":false,"sender":{"key":"bc@mpbell.io","avatar":null},"body":"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? \n\nThanks!\nBlake. \n"},{"id":"481852","messageId":"ZQN9Azt/K28WLfqH@tapette.crustytoothpaste.net","threadId":"60231","inReplyTo":"AB6A85F5-3E76-4462-931E-AD76E0066C37@mpbell.io","subject":"Re: skip-worktree autostash on pull","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2023-09-14T21:37:07Z","receivedAt":"2023-09-14T21:37:12Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2023-09-14 at 09:54:30, Blake Campbell wrote:\n> Hi all - I use update-index --skip-worktree on some config files that\n> I change locally and don’t want to commit, but every time I pull from\n> the remote I have to go through a process of no-skip-worktree, stash,\n> pull, stash pop, then skip-worktree again, which is all a bit tedious!\n> Ideally some switch like --autostash for git pull would be really\n> useful. Does anyone know if something like that exists? \n\nThe Git FAQ[0] outlines that, as you've noticed, skip-worktree doesn't\nwork for ignoring changes to tracked files:\n\n  Git doesn’t provide a way to do this. The reason is that if Git needs\n  to overwrite this file, such as during a checkout, it doesn’t know\n  whether the changes to the file are precious and should be kept, or\n  whether they are irrelevant and can safely be destroyed. Therefore, it\n  has to take the safe route and always preserve them.\n\n  It’s tempting to try to use certain features of git update-index,\n  namely the assume-unchanged and skip-worktree bits, but these don’t\n  work properly for this purpose and shouldn’t be used this way.\n\nIf you take the advice in the FAQ, then the config files won't be\ntracked and you won't have this problem:\n\n  If your goal is to modify a configuration file, it can often be\n  helpful to have a file checked into the repository which is a template\n  or set of defaults which can then be copied alongside and modified as\n  appropriate. This second, modified file is usually ignored to prevent\n  accidentally committing it.\n\nYour particular case is one of many reasons we suggest this approach.\nThere is in fact an --autostash argument in git pull, as well as git\nrebase, both of which work as you might expect, but in general they\nstill won't work properly with --skip-worktree and given the FAQ entry\nabove, we wouldn't add support for that in the option.\n\n[0] https://git-scm.com/docs/gitfaq#ignore-tracked-files\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"481854","messageId":"xmqq7cosifq3.fsf@gitster.g","threadId":"60231","inReplyTo":"ZQN9Azt/K28WLfqH@tapette.crustytoothpaste.net","subject":"Re: skip-worktree autostash on pull","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-14T21:53:40Z","receivedAt":"2023-09-14T21:53:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> Your particular case is one of many reasons we suggest this approach.\n> There is in fact an --autostash argument in git pull, as well as git\n> rebase, both of which work as you might expect, but in general they\n> still won't work properly with --skip-worktree and given the FAQ entry\n> above, we wouldn't add support for that in the option.\n\nAs you mentioned, \"--autostash\" will move away the local change\nwhile your otherwise clean working tree needs to be updated from the\nupstream via \"git pull\" (or \"git pull --rebase\").  So the only thing\nthe user may want to be careful would be \"git commit -a\" (and \"git\nadd -u\"), I would think.  A pre-commit hook should be able to stop\nyou from committing with local changes to these selected paths you\nwant to keep following the upstream _with_ local changes (i.e. run\n\"diff --cached --name-only HEAD\" and exit with non-zero when one of\nthese paths appear in its output).  Upon seeing such a failure, you\ncan \"git stash\" the changes, then \"git commit\" again.  And you do\nnot need to abuse assume-unchanged or skip-worktree for doing that.\n\n\n\n"}]}