threads / discuss / 57805

Git stash create with untracked files?

Subject: Git stash create with untracked files?

## tl;dr

2 messages between Apr 27, 2022 and Apr 27, 2022.

replies: 1people: 2as markdown or json

Tao Klerks· Apr 27, 2022, 10:42 UTC · lore
Hi folks,

I'm just checking in case I'm missing something: Is there any way to tell "git stash create" to include untracked files?

Someone recently brought up a situation where they'd like to take a working directory state (incl untracked but not-ignored files), and reproduce it in another working directory on another machine; "git stash create" seems to be ideal for this purpose, save for the (apparent) lack of arguments support.

If this is not possible today and we wanted to better support this usecase, what would be a sensible way to do it? I can see three possible directions:

1) Change the "create" subcommand to treat specific options as options
rather than the stash message (and make it understand -u /
--include-untracked)
2) Create a new subcommand like "create" that actually supported
relevant options (--include-untracked, --staged, maybe also
pathspecs), without changing the contract of "create"
3) Add an option to the "save" subcommand, asking it to actually leave
the working tree untouched (like create does) - and then expect the
user of this usecase to "drop".

It's possible to just use the existing "push" and then immediately "pop", but the resulting temporary changes to the working tree could make things like IDEs go into an unhappy indexing frenzy, depending on the amount of local change.

I realize there's the "make stashes refs" work ongoing that's related to this, but I don't think I've seen anything there that directly addresses this "make my local changes be available over there *without* touching my working tree" requirement.

Thanks, Tao

brian m. carlson· Apr 27, 2022, 21:54 UTC · re: Tao Klerks · lore

Re: Git stash create with untracked files?

On 2022-04-27 at 10:42:51, Tao Klerks wrote:
Show 10 quoted lines
> Hi folks,
> 
> I'm just checking in case I'm missing something: Is there any way to
> tell "git stash create" to include untracked files?
> 
> Someone recently brought up a situation where they'd like to take a
> working directory state (incl untracked but not-ignored files), and
> reproduce it in another working directory on another machine; "git
> stash create" seems to be ideal for this purpose, save for the
> (apparent) lack of arguments support.
I don't think there's support for that right now, looking at the code.
Show 7 quoted lines
> If this is not possible today and we wanted to better support this
> usecase, what would be a sensible way to do it? I can see three
> possible directions:
> 
> 1) Change the "create" subcommand to treat specific options as options
> rather than the stash message (and make it understand -u /
> --include-untracked)

This seems reasonable. do_create_stash already takes several arguments specifying what to include, so it's probably just a matter of parsing options in create_stash and passing the proper arguments to do_create_stash.

-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

← back to recent threads