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

From: DeMarcus <[email-masked]>
Date: Mon, 19 Dec 2011 22:43:07 +0100

On 2011-12-19 17:18, Dirk Süsserott wrote:
> Am 18.12.2011 16:10 schrieb DeMarcus:
> [...]
>
>>>> 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.
>>>
>>
>> It feels strange doing a commit of partial work. Some of the files may
>> not even be supposed to be checked in.
>>
>>> You could also just checkout different branches in different
>>> directories. Nothing wrong with doing that in git.
>>>
>>
>> Ok thanks, that would give me the same behavior as I have today.
>>
>> However, I can see some benefits with have everything in the same
>> directory as git allows compared to other VCSs. And since the stashing
>> feature is already there in git, it would be nice if the git checkout
>> with some flag could use stashing automatically.
>>
>>
>
> DeMarcus,
>
> probably a post-checkout hook could help you with autostashing, but that
> would need some scripting. Have a look at "git hooks --help".
> I sometimes use such a hook to auto-update submodules when checking out
> a branch. To be fair: I don't know how to identify the "right" stash then.
>

Thanks! I'll check that out. Maybe the right stash could be checked-in 
itself somehow.