* How can I do an automatic stash when doing a checkout?
@ 2011-12-18 11:19 DeMarcus
2011-12-18 11:45 ` Bruce Stephens brs
0 siblings, 1 reply; 9+ messages in thread
From: DeMarcus @ 2011-12-18 11:19 UTC (permalink / raw)
To: git
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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-18 11:19 How can I do an automatic stash when doing a checkout? DeMarcus
@ 2011-12-18 11:45 ` Bruce Stephens brs
2011-12-18 15:10 ` DeMarcus
0 siblings, 1 reply; 9+ messages in thread
From: Bruce Stephens brs @ 2011-12-18 11:45 UTC (permalink / raw)
To: DeMarcus; +Cc: git
DeMarcus <demarcus@hotmail.com> writes:
[...]
> 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.
[...]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-18 11:45 ` Bruce Stephens brs
@ 2011-12-18 15:10 ` DeMarcus
2011-12-18 15:37 ` Bruce Stephens brs
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: DeMarcus @ 2011-12-18 15:10 UTC (permalink / raw)
To: git
>> 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.
>
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-18 15:10 ` DeMarcus
@ 2011-12-18 15:37 ` Bruce Stephens brs
2011-12-19 16:18 ` Dirk Süsserott
2011-12-19 17:24 ` Holger Hellmuth
2 siblings, 0 replies; 9+ messages in thread
From: Bruce Stephens brs @ 2011-12-18 15:37 UTC (permalink / raw)
To: DeMarcus; +Cc: git
DeMarcus <demarcus@hotmail.com> writes:
[...]
> It feels strange doing a commit of partial work. Some of the files may
> not even be supposed to be checked in.
Well, maybe forget about files that you don't expect to keep, but
committing partial work is fine. It's only in your local checkout,
after all; once you've got something worth sharing you can rearrange the
commits so they make sense.
[...]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-18 15:10 ` DeMarcus
2011-12-18 15:37 ` Bruce Stephens brs
@ 2011-12-19 16:18 ` Dirk Süsserott
2011-12-19 21:43 ` DeMarcus
2011-12-19 17:24 ` Holger Hellmuth
2 siblings, 1 reply; 9+ messages in thread
From: Dirk Süsserott @ 2011-12-19 16:18 UTC (permalink / raw)
To: DeMarcus; +Cc: git
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.
And also have a look at the script "git-new-workdir". It comes with git
but in some contrib directory or so. It's not in the $PATH by default.
It allows different working dirs for different branches; some of my
co-workers use it and like it. It won't work with Windows, I guess,
because it makes use of symlinks.
Dirk
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-18 15:10 ` DeMarcus
2011-12-18 15:37 ` Bruce Stephens brs
2011-12-19 16:18 ` Dirk Süsserott
@ 2011-12-19 17:24 ` Holger Hellmuth
2011-12-19 21:46 ` DeMarcus
2 siblings, 1 reply; 9+ messages in thread
From: Holger Hellmuth @ 2011-12-19 17:24 UTC (permalink / raw)
To: DeMarcus; +Cc: git
On 18.12.2011 16:10, DeMarcus wrote:
>> 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 have heard of "git commit --amend" ? Makes partial commits really
easy to work with.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-19 16:18 ` Dirk Süsserott
@ 2011-12-19 21:43 ` DeMarcus
0 siblings, 0 replies; 9+ messages in thread
From: DeMarcus @ 2011-12-19 21:43 UTC (permalink / raw)
To: git
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.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-19 17:24 ` Holger Hellmuth
@ 2011-12-19 21:46 ` DeMarcus
2011-12-19 22:24 ` Junio C Hamano
0 siblings, 1 reply; 9+ messages in thread
From: DeMarcus @ 2011-12-19 21:46 UTC (permalink / raw)
To: git
On 2011-12-19 18:24, Holger Hellmuth wrote:
> On 18.12.2011 16:10, DeMarcus wrote:
>>> 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 have heard of "git commit --amend" ? Makes partial commits really
> easy to work with.
>
>
Yes, I know that one. It's just that I know myself, I don't really like
to go back rearranging. I prefer to keep things spread out at first and
then inserted properly when it's time. But maybe I'm just unused to the
git workflow.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: How can I do an automatic stash when doing a checkout?
2011-12-19 21:46 ` DeMarcus
@ 2011-12-19 22:24 ` Junio C Hamano
0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2011-12-19 22:24 UTC (permalink / raw)
To: DeMarcus; +Cc: git
DeMarcus <demarcus@hotmail.com> writes:
> ... I don't really like to go back rearranging. I prefer to keep things
> spread out at first and then inserted properly when it's time. But maybe
> I'm just unused to the git workflow.
That does not have to do much with "the" git workflow.
If you are a kind of person who likes to work on N things concurrently
without ever making and recording mistakes but would rather keep
unfinished work without committing until done, you would need to have them
in your working trees. By definition you would need to use N working
trees, each of which permanently checks out its own branch, instead of a
single working tree where you checkout one of N branches at a time to work
on.
That is also a perfectly fine git workflow that we support with the
contributed script git-new-workdir.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2011-12-19 22:25 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-18 11:19 How can I do an automatic stash when doing a checkout? DeMarcus
2011-12-18 11:45 ` Bruce Stephens brs
2011-12-18 15:10 ` DeMarcus
2011-12-18 15:37 ` Bruce Stephens brs
2011-12-19 16:18 ` Dirk Süsserott
2011-12-19 21:43 ` DeMarcus
2011-12-19 17:24 ` Holger Hellmuth
2011-12-19 21:46 ` DeMarcus
2011-12-19 22:24 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).