# Commit to other branch

4 messages from 2010-05-31 to 2010-06-06. Participants: Johannes Schneider, Matthieu Moy, Jeff King, Jan Hudec.
Thread: https://gitlist.dev/t/23955

## Johannes Schneider, 2010-05-31 15:46

Subject: Commit to other branch
Message-ID: <4C03D9C1.1060404@cedarsoft.com>
URL: https://gitlist.dev/e/4C03D9C1.1060404%40cedarsoft.com

```
Hi guys,

I often run in that scenario:
I see a small bugfix/typo/missing documentation. Of course I just add a
bit of code to fix that issue...
Then I'd like to commit that change as own commit. And most of the time
this is possible without any problems (git commit <file>).
But as I am *always* working on a topic branch, it takes some work to
commit that change to another branch.

I tried to "git stash "
But then *all* changes are stashed (including my changes)...

So at the moment I do that:

git commit <file> (on wrong branch)
git stash
git checkout pu
git cherry-pick
git checkout my-topic
git reset --hard
git stash apply

And that is much to much work. I just want to do something like that:

git commit <file> -b pu

But I don't think that is possible at the moment... Any hints, how I
could solve that? How do you do that?


Thanks,

Johannes

-- 
Johannes Schneider - blog.cedarsoft.com

```

## Matthieu Moy, 2010-05-31 16:28

Subject: Re: Commit to other branch
Message-ID: <vpq8w70m3wf.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq8w70m3wf.fsf%40bauges.imag.fr
In-Reply-To: <4C03D9C1.1060404@cedarsoft.com>

```
Johannes Schneider <mailings@cedarsoft.com> writes:

> I tried to "git stash "
> But then *all* changes are stashed (including my changes)...

Not completely answering the question, but "git stash -k"
(--keep-index) allows you to do a selective stash. If you have
relevant changes staged, and want to commit the unstaged ones
elsewhere, you can do something like

git stash -k
git checkout elsewhere
git commit
git checkout back-to-your-branch
git stash pop

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

```

## Jeff King, 2010-05-31 23:50

Subject: Re: Commit to other branch
Message-ID: <20100531235016.GB13698@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20100531235016.GB13698%40sigill.intra.peff.net
In-Reply-To: <vpq8w70m3wf.fsf@bauges.imag.fr>

```
On Mon, May 31, 2010 at 06:28:48PM +0200, Matthieu Moy wrote:

> Johannes Schneider <mailings@cedarsoft.com> writes:
> 
> > I tried to "git stash "
> > But then *all* changes are stashed (including my changes)...
> 
> Not completely answering the question, but "git stash -k"
> (--keep-index) allows you to do a selective stash. If you have

Also, recent versions of git have "git stash -p" to interactively stash
just a few changes.

-Peff

```

## Jan Hudec, 2010-06-06 18:43

Subject: Re: Commit to other branch
Message-ID: <20100606184334.GB30035@efreet.light.src>
URL: https://gitlist.dev/e/20100606184334.GB30035%40efreet.light.src
In-Reply-To: <4C03D9C1.1060404@cedarsoft.com>

```
On Mon, May 31, 2010 at 17:46:09 +0200, Johannes Schneider wrote:
> I often run in that scenario:
> I see a small bugfix/typo/missing documentation. Of course I just add a
> bit of code to fix that issue...
> Then I'd like to commit that change as own commit. And most of the time
> this is possible without any problems (git commit <file>).
> But as I am *always* working on a topic branch, it takes some work to
> commit that change to another branch.

What I'd probably do is just commit the quick fix, as separate commit, where
I am. Than when I'd have a bit of time (probably when I'd otherwise think of
rebasing on master anyway) I'd rebase -i all such fixes to the bottom of the
topic branch, go to master and merge just those fixes. The rebase -i can be
against current master, so the merge back would be fast-forward, of course.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

```
