# [PATCH] Add option to git-branch to set up automatic rebasing

7 messages from 2008-06-19 to 2008-06-19. Participants: Pieter de Bie, Johannes Schindelin, Björn Steinbrink, Junio C Hamano.
Thread: https://gitlist.dev/t/14026

## Pieter de Bie, 2008-06-19 00:53

Subject: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <1213836802-3163-1-git-send-email-pdebie@ai.rug.nl>
URL: https://gitlist.dev/e/1213836802-3163-1-git-send-email-pdebie%40ai.rug.nl

```
This functionality was actually introduced in
 0a02186f924aee1bd69f18ed01f645aa332ce0d1, but can only be activated by the
configuration flag. Now we can also setup auto rebasing using the --rebase
flag in git-branch or git-checkout, similar to how --track works.

Signed-off-by: Pieter de Bie <pdebie@ai.rug.nl>
---
 Documentation/git-branch.txt   |   12 ++++++++++--
 Documentation/git-checkout.txt |   11 ++++++++---
 builtin-branch.c               |   10 ++++++++--
 builtin-checkout.c             |    9 ++++++++-
 4 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt
index 0fd5808..81144d1 100644
--- a/Documentation/git-branch.txt
+++ b/Documentation/git-branch.txt
@@ -11,7 +11,8 @@ SYNOPSIS
 'git-branch' [--color | --no-color] [-r | -a] [--merged | --no-merged]
 	   [-v [--abbrev=<length> | --no-abbrev]]
 	   [--contains <commit>]
-'git-branch' [--track | --no-track] [-l] [-f] <branchname> [<start-point>]
+'git-branch' [--track | --no-track | --rebase] [-l] [-f]
+	   <branchname> [<start-point>]
 'git-branch' (-m | -M) [<oldbranch>] <newbranch>
 'git-branch' (-d | -D) [-r] <branchname>...
 
@@ -40,7 +41,9 @@ When a local branch is started off a remote branch, git sets up the
 branch so that linkgit:git-pull[1] will appropriately merge from
 the remote branch. This behavior may be changed via the global
 `branch.autosetupmerge` configuration flag. That setting can be
-overridden by using the `--track` and `--no-track` options.
+overridden by using the `--track` and `--no-track` options. If you use
+--rebase, the branch will be set up to rebase instead of merge on pull.
+This can also be set to the default by the 'branch.autosetuprebase' flag.
 
 With a '-m' or '-M' option, <oldbranch> will be renamed to <newbranch>.
 If <oldbranch> had a corresponding reflog, it is renamed to match
@@ -121,6 +124,11 @@ OPTIONS
 --no-track::
 	Ignore the branch.autosetupmerge configuration variable.
 
+--rebase::
+	Does the same as --track, with the exception that subsequent pulls
+	will do a rebase, not a pull. This is the same as using "git pull
+	--rebase" to update the branch.
+
 --contains <commit>::
 	Only list branches which contain the specified commit.
 
diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 3ad9760..eb114a2 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -8,7 +8,7 @@ git-checkout - Checkout a branch or paths to the working tree
 SYNOPSIS
 --------
 [verse]
-'git-checkout' [-q] [-f] [[--track | --no-track] -b <new_branch> [-l]] [-m] [<branch>]
+'git-checkout' [-q] [-f] [[--track | --no-track | --rebase] -b <new_branch> [-l]] [-m] [<branch>]
 'git-checkout' [<tree-ish>] <paths>...
 
 DESCRIPTION
@@ -18,8 +18,8 @@ When <paths> are not given, this command switches branches by
 updating the index and working tree to reflect the specified
 branch, <branch>, and updating HEAD to be <branch> or, if
 specified, <new_branch>.  Using -b will cause <new_branch> to
-be created; in this case you can use the --track or --no-track
-options, which will be passed to `git branch`.
+be created; in this case you can use the --track, --no-track
+and --rebase options, which will be passed to `git branch`.
 
 When <paths> are given, this command does *not* switch
 branches.  It updates the named paths in the working tree from
@@ -63,6 +63,11 @@ OPTIONS
 --no-track::
 	Ignore the branch.autosetupmerge configuration variable.
 
+--rebase::
+	Does the same as --track, with the exception that subsequent pulls
+	will do a rebase, not a pull. This is the same as using "git pull
+	--rebase" to update the branch.
+
 -l::
 	Create the new branch's reflog.  This activates recording of
 	all changes made to the branch ref, enabling use of date
diff --git a/builtin-branch.c b/builtin-branch.c
index d279702..b1ba920 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -18,7 +18,7 @@ static const char * const builtin_branch_usage[] = {
 	"git-branch [options] [-r | -a] [--merged | --no-merged]",
 	"git-branch [options] [-l] [-f] <branchname> [<start-point>]",
 	"git-branch [options] [-r] (-d | -D) <branchname>",
-	"git-branch [options] (-m | -M) [<oldbranch>] <newbranch>",
+	"git-branch [options] [--track | --no-track | --rebase] (-m | -M) [<oldbranch>] <newbranch>",
 	NULL
 };
 
@@ -425,7 +425,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 {
 	int delete = 0, rename = 0, force_create = 0;
 	int verbose = 0, abbrev = DEFAULT_ABBREV, detached = 0;
-	int reflog = 0;
+	int reflog = 0, rebase = 0;
 	enum branch_track track;
 	int kinds = REF_LOCAL_BRANCH;
 	struct commit_list *with_commit = NULL;
@@ -457,6 +457,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		OPT_BIT('M', NULL, &rename, "move/rename a branch, even if target exists", 2),
 		OPT_BOOLEAN('l', NULL, &reflog, "create the branch's reflog"),
 		OPT_BOOLEAN('f', NULL, &force_create, "force creation (when already exists)"),
+		OPT_BOOLEAN(0, "rebase", &rebase, "Setup automatic rebasing. Implies --track"),
 		OPT_SET_INT(0, "merged", &mergefilter, "list only merged branches", 1),
 		OPT_END(),
 	};
@@ -471,6 +472,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	if (!!delete + !!rename + !!force_create > 1)
 		usage_with_options(builtin_branch_usage, options);
 
+	if (rebase) {
+		autorebase = AUTOREBASE_ALWAYS;
+		track = BRANCH_TRACK_EXPLICIT;
+	}
+
 	head = resolve_ref("HEAD", head_sha1, 0, NULL);
 	if (!head)
 		die("Failed to resolve HEAD as a valid ref.");
diff --git a/builtin-checkout.c b/builtin-checkout.c
index 93ea69b..ee4fb09 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -500,6 +500,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	struct checkout_opts opts;
 	unsigned char rev[20];
 	const char *arg;
+	int rebase = 0;
 	struct branch_info new;
 	struct tree *source_tree = NULL;
 	struct option options[] = {
@@ -508,6 +509,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN('l', NULL, &opts.new_branch_log, "log for new branch"),
 		OPT_SET_INT('t', "track",  &opts.track, "track",
 			BRANCH_TRACK_EXPLICIT),
+		OPT_BOOLEAN(0, "rebase", &rebase, "Setup automatic rebasing. Implies --track"),
 		OPT_BOOLEAN('f', NULL, &opts.force, "force"),
 		OPT_BOOLEAN('m', NULL, &opts.merge, "merge"),
 		OPT_END(),
@@ -521,6 +523,11 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	opts.track = git_branch_track;
 
 	argc = parse_options(argc, argv, options, checkout_usage, 0);
+	if (rebase) {
+		autorebase = AUTOREBASE_ALWAYS;
+		opts.track = BRANCH_TRACK_EXPLICIT;
+	}
+
 	if (argc) {
 		arg = argv[0];
 		if (get_sha1(arg, rev))
@@ -548,7 +555,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
 	}
 
 	if (!opts.new_branch && (opts.track != git_branch_track))
-		die("git checkout: --track and --no-track require -b");
+		die("git checkout: --track, --no-track and --rebase require -b");
 
 	if (opts.force && opts.merge)
 		die("git checkout: -f and -m are incompatible");
-- 
1.5.6.rc1.153.gc1d96

```

## Johannes Schindelin, 2008-06-19 14:00

Subject: Re: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <alpine.DEB.1.00.0806191459150.6439@racer>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0806191459150.6439%40racer
In-Reply-To: <1213836802-3163-1-git-send-email-pdebie@ai.rug.nl>

```
Hi,

On Thu, 19 Jun 2008, Pieter de Bie wrote:

> This functionality was actually introduced in
>  0a02186f924aee1bd69f18ed01f645aa332ce0d1, but can only be activated by the
> configuration flag. Now we can also setup auto rebasing using the --rebase
> flag in git-branch or git-checkout, similar to how --track works.

How about "--rebasing"?  I would scratch my head a bit how a new branch 
and a rebase would go together.

Ciao,
Dscho

```

## Pieter de Bie, 2008-06-19 14:10

Subject: Re: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <FCE0735F-3CF9-4F7D-AA1B-FA9D8EA8C593@ai.rug.nl>
URL: https://gitlist.dev/e/FCE0735F-3CF9-4F7D-AA1B-FA9D8EA8C593%40ai.rug.nl
In-Reply-To: <alpine.DEB.1.00.0806191459150.6439@racer>

```

On 19 jun 2008, at 16:00, Johannes Schindelin wrote:

> How about "--rebasing"?  I would scratch my head a bit how a new  
> branch
> and a rebase would go together.

Perhaps even --auto-rebase then? I agree it sounds confusing

- Pieter

```

## Björn Steinbrink, 2008-06-19 15:43

Subject: Re: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <20080619154350.GA21625@atjola.homenet>
URL: https://gitlist.dev/e/20080619154350.GA21625%40atjola.homenet
In-Reply-To: <alpine.DEB.1.00.0806191459150.6439@racer>

```
On 2008.06.19 15:00:19 +0100, Johannes Schindelin wrote:
> Hi,
> 
> On Thu, 19 Jun 2008, Pieter de Bie wrote:
> 
> > This functionality was actually introduced in
> >  0a02186f924aee1bd69f18ed01f645aa332ce0d1, but can only be activated by the
> > configuration flag. Now we can also setup auto rebasing using the --rebase
> > flag in git-branch or git-checkout, similar to how --track works.
> 
> How about "--rebasing"?  I would scratch my head a bit how a new branch 
> and a rebase would go together.

Hm, --rebasing sounds weird to me as well. Maybe --track=merge and
--track=rebase, with --track being equal to --track=merge?

Björn

```

## Junio C Hamano, 2008-06-19 19:14

Subject: Re: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <7vr6attey8.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr6attey8.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080619154350.GA21625@atjola.homenet>

```
Björn Steinbrink <B.Steinbrink@gmx.de> writes:

> On 2008.06.19 15:00:19 +0100, Johannes Schindelin wrote:
>> Hi,
>> 
>> On Thu, 19 Jun 2008, Pieter de Bie wrote:
>> 
>> > This functionality was actually introduced in
>> >  0a02186f924aee1bd69f18ed01f645aa332ce0d1, but can only be activated by the
>> > configuration flag. Now we can also setup auto rebasing using the --rebase
>> > flag in git-branch or git-checkout, similar to how --track works.
>> 
>> How about "--rebasing"?  I would scratch my head a bit how a new branch 
>> and a rebase would go together.
>
> Hm, --rebasing sounds weird to me as well. Maybe --track=merge and
> --track=rebase, with --track being equal to --track=merge?

That looks like the best wording so far, although I suspect that the true
reason why all of the above sounds confusing may be because the concept
itself is not clear.

```

## Pieter de Bie, 2008-06-19 22:58

Subject: Re: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <12AB50C8-6CBF-4D96-8FAB-90234A9006D0@ai.rug.nl>
URL: https://gitlist.dev/e/12AB50C8-6CBF-4D96-8FAB-90234A9006D0%40ai.rug.nl
In-Reply-To: <7vr6attey8.fsf@gitster.siamese.dyndns.org>

```

On 19 jun 2008, at 21:14, Junio C Hamano wrote:

>> Hm, --rebasing sounds weird to me as well. Maybe --track=merge and
>> --track=rebase, with --track being equal to --track=merge?
>
> That looks like the best wording so far, although I suspect that the  
> true
> reason why all of the above sounds confusing may be because the  
> concept
> itself is not clear.

That's why I suggested --auto-rebase, which is more verbose in what
it does. Perhaps we should add it as an optional flag for --track, like

   git branch --track --auto-rebase local remote/branch

? That is a bit long though.

I don't think "--track=rebase" makes a lot of sense, since "track" is
still a boolean in my head ;)

```

## Junio C Hamano, 2008-06-19 23:24

Subject: Re: [PATCH] Add option to git-branch to set up automatic rebasing
Message-ID: <7vabhhroth.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vabhhroth.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <12AB50C8-6CBF-4D96-8FAB-90234A9006D0@ai.rug.nl>

```
Pieter de Bie <pdebie@ai.rug.nl> writes:

> That's why I suggested --auto-rebase, which is more verbose in what
> it does. Perhaps we should add it as an optional flag for --track, like
>
>   git branch --track --auto-rebase local remote/branch
>
> ? That is a bit long though.

That does not make _any_ sense unless you also have --auto-merge.  And
which part of rebasing is auto anyway?  "git checkout local" won't rebase
onto remote/branch for one thing.

> I don't think "--track=rebase" makes a lot of sense, since "track" is
> still a boolean in my head ;)

Well, track _is_ boolean.  You usually build and develop yourself, but if
you are following somebody else, you say "this is not really a pure
development but is used to trail somebody else (aka "track mode ON"), and
the way for this branch to follow that somebody else specifically is to
merge from it or rebase on top of it (aka "how it tracks")".

```
