Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH/RFC] Convenient support of remote branches in git-checkout
Date: Mon, 06 Nov 2006 16:13:44 -0800	[thread overview]
Message-ID: <7vd580azbb.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <200611070026.16425.Josef.Weidendorfer@gmx.de> (Josef Weidendorfer's message of "Tue, 7 Nov 2006 00:26:16 +0100")

Josef Weidendorfer <Josef.Weidendorfer@gmx.de> writes:

> Example to hack on git's next branch:
>
>  git-clone --use-separate-remote http://www.kernel.org/pub/scm/git/git.git
>  cd git
>  git-checkout origin/next
>  <hack on next>
>  git pull (to merge patches from remote 'next')
>
> The checkout creates local branch 'next' to checkout read-only
> remote branch 'remotes/origin/next'. Additionally, it sets up
> 'remotes/origin/next' from remote repository 'origin' as
> default merge source for the new development branch.

I am disturbed by an inconsistency here.

> +	if git-show-ref --verify --quiet -- "refs/heads/$newbranch"
> +	then
> +		echo "Proposed new branch '$newbranch' to checkout...
> +		echo "To checkout, specify a new branch name with -b"
> +		exit 1
> +	fi

This logic is guarding against already having a local branch
that is called 'next', and that is why the "Proposed new branch"
message needs to be there.  One explanation of why 'next' exists
in the local branch namespace in the first place is probably
there are other remote branches than origin that have 'next' and
the user previously checked it out.  Or perhaps the user has
already done this "checkout origin/next" once already.

I wonder if it is more consistent and easy to use to just make
this:

	git checkout origin/next

a synonym to:

	git checkout -b origin/next remotes/origin/next

when remotes/origin/next exists and heads/origin/next does not.

Then "git checkout origin/next" would always mean "I want to
switch to the branch I use to hack on the branch 'next' Junio
has".  Do it once and you will get exactly my tip, hack on it,
switch out of it and then do it again and you won't lose your
previous work but just switch to that branch.

That is, something like this...

---

diff --git a/git-checkout.sh b/git-checkout.sh
index 119bca1..f6486c6 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -4,6 +4,16 @@ USAGE='[-f] [-b <new_branch>] [-m] [<bra
 SUBDIRECTORY_OK=Sometimes
 . git-sh-setup
 
+# Automatic forking of local branch based on remote
+if test $# = 1 &&
+   git show-ref --verify --quiet -- "refs/remotes/$1" &&
+   ! git show-ref --verify --quiet -- "refs/heads/$1"
+then
+	set x -b "$1" "remotes/$1"
+	echo >&2 "* Forking local branch $1 off of remotes/$1..."
+	shift
+fi
+
 old_name=HEAD
 old=$(git-rev-parse --verify $old_name 2>/dev/null)
 new=

  parent reply	other threads:[~2006-11-07  0:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-06 23:26 [PATCH/RFC] Convenient support of remote branches in git-checkout Josef Weidendorfer
2006-11-06 23:30 ` Josef Weidendorfer
2006-11-07  0:13 ` Junio C Hamano [this message]
2006-11-07  1:25   ` Josef Weidendorfer
2006-11-07  2:03     ` Junio C Hamano
2006-11-07  2:08       ` Junio C Hamano
2006-11-07 10:18         ` Josef Weidendorfer
2006-11-07  2:27     ` Junio C Hamano
2006-11-07 10:28       ` Josef Weidendorfer
2006-11-07  6:54     ` Karl Hasselström
2006-11-07 10:53       ` Josef Weidendorfer
2006-11-07 13:56         ` Karl Hasselström
2006-11-07 17:04           ` Josef Weidendorfer
2006-11-07  7:07     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vd580azbb.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=Josef.Weidendorfer@gmx.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox