# [RFC] checkout --rebase

6 messages from 2013-07-19 to 2013-07-19. Participants: Ramkumar Ramachandra, Sebastian Staudt.
Thread: https://gitlist.dev/t/34488

## Ramkumar Ramachandra, 2013-07-19 10:21

Subject: [RFC] checkout --rebase
Message-ID: <CALkWK0m-ZpVvvgAB_yzooah0=veeNDudahs=4ur2YHN03h-h4g@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0m-ZpVvvgAB_yzooah0%3DveeNDudahs%3D4ur2YHN03h-h4g%40mail.gmail.com

```
Hi,

I'm often work on small topic branches, and find myself doing this quite often:

  # on branch master
  $ git checkout um-build
  $ git rebase master

This is horribly inefficient; the first operation takes a _really_
long time to complete, since master updates itself very often and I
have to check out an old worktree.  So, I work around this issue by
doing:

  # on branch master
  $ git checkout -b um-build-2
  $ git cherry-pick ..um-build
  $ git branch -M um-build

... and I scripted it.  Perhaps we should get this functionality in
core, as `git checkout --rebase` (or something)?

Thanks.

```

## Sebastian Staudt, 2013-07-19 10:48

Subject: Re: [RFC] checkout --rebase
Message-ID: <CA+xP2SbHD+MU4K0JBbZdA6bWQFQerBi5mWA+7G9=tBksjp+LXw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BxP2SbHD%2BMU4K0JBbZdA6bWQFQerBi5mWA%2B7G9%3DtBksjp%2BLXw%40mail.gmail.com
In-Reply-To: <CALkWK0m-ZpVvvgAB_yzooah0=veeNDudahs=4ur2YHN03h-h4g@mail.gmail.com>

```
Isn't this what you want?

 $ git rebase master um-build


2013/7/19 Ramkumar Ramachandra <artagnon@gmail.com>:
> Hi,
>
> I'm often work on small topic branches, and find myself doing this quite often:
>
>   # on branch master
>   $ git checkout um-build
>   $ git rebase master
>
> This is horribly inefficient; the first operation takes a _really_
> long time to complete, since master updates itself very often and I
> have to check out an old worktree.  So, I work around this issue by
> doing:
>
>   # on branch master
>   $ git checkout -b um-build-2
>   $ git cherry-pick ..um-build
>   $ git branch -M um-build
>
> ... and I scripted it.  Perhaps we should get this functionality in
> core, as `git checkout --rebase` (or something)?
>
> Thanks.
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```

## Ramkumar Ramachandra, 2013-07-19 11:10

Subject: Re: [RFC] checkout --rebase
Message-ID: <CALkWK0nM4fkCPNJo_c3Rpwh1azsGRdGvM3S80vcuRiRXDT0vOQ@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0nM4fkCPNJo_c3Rpwh1azsGRdGvM3S80vcuRiRXDT0vOQ%40mail.gmail.com
In-Reply-To: <CA+xP2SbHD+MU4K0JBbZdA6bWQFQerBi5mWA+7G9=tBksjp+LXw@mail.gmail.com>

```
Sebastian Staudt wrote:
> Isn't this what you want?
>
>  $ git rebase master um-build

Ha, yes.  Sorry about the stupidity.

```

## Ramkumar Ramachandra, 2013-07-19 11:33

Subject: Re: [RFC] checkout --rebase
Message-ID: <CALkWK0kVNw3Ko3+_Y-KDF=pdha6wxyMmQmLtOOr5tQYzgUr_Mw@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0kVNw3Ko3%2B_Y-KDF%3Dpdha6wxyMmQmLtOOr5tQYzgUr_Mw%40mail.gmail.com
In-Reply-To: <CALkWK0nM4fkCPNJo_c3Rpwh1azsGRdGvM3S80vcuRiRXDT0vOQ@mail.gmail.com>

```
Ramkumar Ramachandra wrote:
> Sebastian Staudt wrote:
>> Isn't this what you want?
>>
>>  $ git rebase master um-build
>
> Ha, yes.  Sorry about the stupidity.

Hm, I'm not entirely sure how to optimize the codepath to eliminate
the checkout.  It seems to be absolutely necessary atleast in the -i
codepath.

Let's inspect when $switch_to is set:

	# Is it "rebase other $branchname" or "rebase other $commit"?
	branch_name="$1"
	switch_to="$1"

$revisions seems to be set correctly, and rebase--am does a
move_to_original_branch as the last step.  So, I wonder if this will
work:

diff --git a/git-rebase.sh b/git-rebase.sh
index 0039ecf..7405d9a 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -542,9 +542,15 @@ then
 	if test -z "$force_rebase"
 	then
 		# Lazily switch to the target branch if needed...
-		test -z "$switch_to" ||
-		GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \
-			git checkout "$switch_to" --
+		if ! test -z "$switch_to"; then
+			if "$type" = am; then
+				GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout -b $switch_to-2" \
+					git checkout -b "$switch_to-2" --
+			else
+				GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \
+					git checkout "$switch_to" --
+			fi
+		fi
 		say "$(eval_gettext "Current branch \$branch_name is up to date.")"
 		finish_rebase
 		exit 0

(ofcourse, we still need a mechanism to remove this temporary
$switch_to-2 branch)

What about rebase--merge?  Can we eliminate the checkout then?

```

## Ramkumar Ramachandra, 2013-07-19 11:36

Subject: Re: [RFC] checkout --rebase
Message-ID: <CALkWK0mp=2xuQwSjMPRBvwRUEnAbM2=r_hZu=ZKc8wxZYxgSVA@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0mp%3D2xuQwSjMPRBvwRUEnAbM2%3Dr_hZu%3DZKc8wxZYxgSVA%40mail.gmail.com
In-Reply-To: <CALkWK0kVNw3Ko3+_Y-KDF=pdha6wxyMmQmLtOOr5tQYzgUr_Mw@mail.gmail.com>

```
Ramkumar Ramachandra wrote:
> diff --git a/git-rebase.sh b/git-rebase.sh
> index 0039ecf..7405d9a 100755
> --- a/git-rebase.sh
> +++ b/git-rebase.sh

Er, sorry.  I think it suffices to check that $branch_name equals
HEAD, for this optimization.

```

## Ramkumar Ramachandra, 2013-07-19 12:31

Subject: Re: [RFC] checkout --rebase
Message-ID: <CALkWK0=vpTHfVsa1QiM75cQL7Ou-_=2=_e-++ZLeeo-d8hqhOw@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0%3DvpTHfVsa1QiM75cQL7Ou-_%3D2%3D_e-%2B%2BZLeeo-d8hqhOw%40mail.gmail.com
In-Reply-To: <CALkWK0mp=2xuQwSjMPRBvwRUEnAbM2=r_hZu=ZKc8wxZYxgSVA@mail.gmail.com>

```
Damn it: checkout doesn't get executed at all because the $mb = $onto
condition fails; I was looking in the wrong place.  It's format-patch
and am that are slowing things down terribly.  Has anyone looked into
stripping out the dependency?  Why is cherry-pick deficient?

My current workaround is to use the faster `--keep-empty` codepath,
but it doesn't persist state on conflict.  Isn't this an undocumented
fact (aka. bug)?

Thanks.

```
