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

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

From
DDeMarcus <demarcus@hotmail.com>
Date
Dec 18, 2011, 11:19 UTC
Message-ID
<jcki8u$oip$1@dough.gmane.org>
Hi,

I'm new to git and currently I'm working with SVN and there it's a bit messier doing branching but once I've branched then all my development there is completely separated from any other branch. When I want to work on another branch I just change directory.

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?

Thanks, Daniel

Next: Bruce Stephens brs
Message 1 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.