threads / patch / 7092

patch, 3 partsgit-checkout: add --track and --no-track options

Subject: [PATCH 3/3] git-checkout: add --track and --no-track options

## tl;dr

One message between Mar 5, 2007 and Mar 5, 2007. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Paolo Bonzini· Mar 5, 2007, 08:57 UTC · lore

This patch adds --track and --no-track options to "git checkout". In order to do so, it modifies the script to use "git branch" to create the branch, and passes the two options to "git branch". The two new options are only allowed when -b is given on the command-line, and they are only effective when the branch is created off a remote branch.

The defaults for remote branch tracking are as for "git branch": it is off by
default, but it can be enabled with the configuration variable
"remote.REMOTENAME.trackintolocalbranches".
---
 Documentation/git-checkout.txt |   15 +++++++++++++--
 git-checkout.sh                |   17 +++++++++++------
 2 files changed, 24 insertions(+), 8 deletions(-)
Show changes to 2 files +24 −8

Documentation/git-checkout.txt, git-checkout.sh

diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt
index 1ae77be..f5b2d50 100644
--- a/Documentation/git-checkout.txt
+++ b/Documentation/git-checkout.txt
@@ -8,7 +8,7 @@ git-checkout - Checkout and switch to a branch
 SYNOPSIS
 --------
 [verse]
-'git-checkout' [-q] [-f] [-b <new_branch> [-l]] [-m] [<branch>]
+'git-checkout' [-q] [-f] [-b [--track | --no-track] <new_branch> [-l]] [-m] [<branch>]
 'git-checkout' [<tree-ish>] <paths>...
 
 DESCRIPTION
@@ -18,7 +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.
+be created; in this case you can use the --track or --no-track
+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
@@ -45,6 +46,16 @@ OPTIONS
 	by gitlink:git-check-ref-format[1].  Some of these checks
 	may restrict the characters allowed in a branch name.
 
+--track::
+	When -b is given and a branch is created off a remote branch,
+	setup so that git-pull will automatically retrieve data from
+	the remote branch.
+
+--no-track::
+	When -b is given and a branch is created off a remote branch,
+	don't setup so that git-pull will not retrieve data from the
+	remote branch independent of the configuration settings.
+
 -l::
 	Create the new branch's ref log.  This activates recording of
 	all changes to made the branch ref, enabling use of date
diff --git a/git-checkout.sh b/git-checkout.sh
index 14835a4..6caa9fd 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -12,6 +12,7 @@ new=
 new_name=
 force=
 branch=
+track=
 newbranch=
 newbranch_log=
 merge=
@@ -33,7 +34,10 @@ while [ "$#" != "0" ]; do
 			die "git checkout: we do not like '$newbranch' as a branch name."
 		;;
 	"-l")
-		newbranch_log=1
+		newbranch_log=-l
+		;;
+	"--track"|"--no-track")
+		track="$arg"
 		;;
 	"-f")
 		force=1
@@ -85,6 +89,11 @@ while [ "$#" != "0" ]; do
     esac
 done
 
+case "$new_branch,$track" in
+,--*)
+	die "git checkout: --track and --no-track require -b"
+esac
+
 case "$force$merge" in
 11)
 	die "git checkout: -f and -m are incompatible"
@@ -235,11 +244,7 @@ fi
 #
 if [ "$?" -eq 0 ]; then
 	if [ "$newbranch" ]; then
-		if [ "$newbranch_log" ]; then
-			mkdir -p $(dirname "$GIT_DIR/logs/refs/heads/$newbranch")
-			touch "$GIT_DIR/logs/refs/heads/$newbranch"
-		fi
-		git-update-ref -m "checkout: Created from $new_name" "refs/heads/$newbranch" $new || exit
+		git-branch $track $newbranch_log "$newbranch" "$new_name" || exit
 		branch="$newbranch"
 	fi
 	if test -n "$branch"
-- 
1.4.4.2

← back to recent threads