{"thread":{"id":"50353","subject":"Extending `git pull` to deal with unindexed changes that would be overwritten","startedAt":"2019-01-29T21:39:08Z","lastAt":"2019-01-29T21:39:08Z","messageCount":1,"participants":["Mahmoud Al-Qudsi"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"368051","messageId":"CACcTrKc_0vWzp3oskhBOQfxu97t=kmg=qeXq7Yg6L8bFvsyRFQ@mail.gmail.com","threadId":"50353","inReplyTo":null,"subject":"Extending `git pull` to deal with unindexed changes that would be overwritten","fromName":"Mahmoud Al-Qudsi","fromEmail":"mqudsi@neosmart.net","sentAt":"2019-01-29T21:38:51Z","receivedAt":"2019-01-29T21:39:08Z","isPatch":false,"sender":{"key":"mqudsi@neosmart.net","avatar":"https://gravatar.com/avatar/c2643dd7c6df61aed49d9f3d917ac6d61cafbbda5f9b1619f50d3b749dca415a?d=mp&s=160"},"body":"Hello all,\n\nA common point of friction when flipping back and forth between branches,\nespecially when dealing with build configurations/artifacts that were sometimes\nincluded in the repository and sometimes not (e.g. the artifacts of an\n`autoreconf` run) is when a file not in the index at all would be overridden by\nthe attempted checkout.\n\ne.g. file `:/foo` is currently not in the index in any way, shape, or form (soft\nor hard) and executing `git checkout bar` would result in a copy of `bar:/foo`\nbeing checked out, which leads git to emit the following notice and abort the\ncheckout:\n\n> error: The following untracked working tree files would be overwritten by\n> checkout:\n>    foo\n\nWhen it's a single file like in the example above, it's easy enough to add it to\nthe index, stash your changes, then retry the checkout. But when there are\nmultiple files involved -- perhaps especially in the presence of other untracked\nfiles you *don't* want to stash -- it's not as straightforward.\n\nI would like to propose two changes extending current git actions to handle such\na scenario:\n\n1) `git pull --autostash` (both with and without `--rebase`, the latter of which\n   is currently not a valid option), which would do the equivalent of calling\n   `git add` on each of the files that would be overwritten followed by `git\n   stash`, and\n2) Either extending `git pull --force` or introducing something along the lines\n   of `git pull --reset` or similar which would forcibly drop the changes that\n   would be overwritten (e.g. equivalent to extension 1 above followed by `git\n   stash drop`) as an alternative to running `git reset --hard` before\n   attempting to repeat the checkout operation but dropping only changes that\n   explicitly conflict with the requested checkout operation (so somewhat less\n   destructive).\n\n(I believe the first proposal should be fairly straightforward and free of\ncontroversy, the second might be a little too dramatic or dangerous to be\naccepted.)\n\nWith regards to the first extension: as mentioned, it is currently an error to\nrun `git pull --autostash` without `--rebase` as well, but currently even the\naccepted `git pull --autostash --rebase` does *not* stash changes to files not\nin the index that would be overwritten by the checkout.\n\nOf course there's an incredibly good chance that I'm missing a git action that\nalready does what's requested that I just don't know about -- in which case,\nplease do enlighten me!\n\nThank you for your consideration,\n\nMahmoud Al-Qudsi\nNeoSmart Technologies\n"}]}