From: Junio C Hamano Date: Tue, 07 Nov 2006 00:13:44 GMT Subject: Re: [PATCH/RFC] Convenient support of remote branches in git-checkout Message-ID: <7vd580azbb.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <200611070026.16425.Josef.Weidendorfer@gmx.de> Josef Weidendorfer 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 > > 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 ] [-m] [&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=