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

Re: defaulting git stash to "--keep-index"

From
Jason St. John <jstjohn@purdue.edu>
Date
Nov 20, 2013, 02:10 UTC
Message-ID
<CAEjxke_FNoj__J0y6JoXiFTAYY7WGDP4ntwJXcJO8=gxASbQCQ@mail.gmail.com>
In-Reply-To
<20131119195009.6d4e183b@bigbox.christie.dr>
On Tue, Nov 19, 2013 at 8:50 PM, Tim Chase <git@tim.thechases.com> wrote:
Show 21 quoted lines
> Having lost "add -p" work enough times when stashing, I finally
> dug into the docs to see how to prevent it, discovering that
> "--keep-index" does exactly what I want.  However, now I have trouble
> remembering to add the "--keep-index" until after I've shot myself in
> the foot.  How do I go about getting "git stash" to default to
> "--keep-index"?  I've played around a little with aliases, but
> haven't found the right incantation.
>
> The existence of "--no-keep-index" suggests there's some way to make
> "--keep-index" the default, but I'm missing it.
>
> Thanks,
>
> -tkc
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

git-config(1) states that you cannot hide existing Git commands. In other words, aliasing "git stash" to "git stash --keep-index" is not possible. You could try playing around with the exclamation point version (e.g. `git config "alias.stash = !git stash --keep-index"`), but I suspect that Git will still not allow you to hide the existing command.

If you are willing to switch to a new command, you can fix this
easily. For example, either of these would do what you want whenever
you run `git stsh` (note the missing "a" in "stash") or `git stashki`:
    `git config "alias.stsh = stash --keep-index"`
    `git config "alias.stashki = stash --keep-index"`
Jason
Previous: Nathan Collins
Message 3 of 3 in “defaulting git stash to "--keep-index"”
  1. Tim ChaseNov 20, 2013
  2. Nathan CollinsNov 20, 2013
  3. Jason St. JohnNov 20, 2013

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.