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

Re: How can I do an automatic stash when doing a checkout?

From
BBBruce Stephens brs <bruce.stephens@isode.com>
Date
Dec 18, 2011, 11:45 UTC
Message-ID
<84ty4ycdcc.fsf@cenderis.demon.co.uk>
In-Reply-To
<jcki8u$oip$1@dough.gmane.org>
DeMarcus <demarcus@hotmail.com> writes:
[...]
Show 12 quoted lines
> This is not how it works with git, where when I want to change branch
> I have to do a git checkout. However, that leaves all the modified and
> untracked files in the directory of the branch I switched to. This is
> seldom the behavior I want.
>
> With the git stash command I can clean the directory the way I want
> but the stash command is not connected to a particular branch.
>
> Is there a way to have git checkout do an automatic stash when doing a
> checkout to another branch, and then do an automatic git stash apply
> with the correct stash when changing back to the previous branch
> again?

You probably don't want to use stash. Just commit whatever partial work you've done.

You could also just checkout different branches in different directories. Nothing wrong with doing that in git.

[...]
Previous: DeMarcusNext: DeMarcus
Message 2 of 9 in “How can I do an automatic stash when doing a checkout?”
  1. DeMarcusDec 18, 2011
  2. Bruce Stephens brsDec 18, 2011
  3. DeMarcusDec 18, 2011
  4. Bruce Stephens brsDec 18, 2011
  5. Dirk SüsserottDec 19, 2011
  6. DeMarcusDec 19, 2011
  7. Holger HellmuthDec 19, 2011
  8. DeMarcusDec 19, 2011
  9. Junio C HamanoDec 19, 2011

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.