git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC] Convenient support of remote branches in git-checkout

From
JWJosef Weidendorfer <josef.weidendorfer@gmx.de>
Date
Nov 7, 2006, 01:25 UTC
Message-ID
<200611070225.24956.Josef.Weidendorfer@gmx.de>
In-Reply-To
<7vd580azbb.fsf@assigned-by-dhcp.cox.net>
On Tuesday 07 November 2006 01:13, Junio C Hamano wrote:
Show 10 quoted lines
> 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.
Interesting.

I wonder how often there is a real need for that long branch names. IMHO this convenience behavior of git-checkout should target the majority of possible use cases. Is it really better to default to long branch names instead of asking for explicit branch name in the rare case of conflict (ie. multiple remote repositories with same branch names and you want to develop on both these branches locally)?

Suppose developer2 uses this scheme, and has a local development branch "junio/next", which is based on your "next" branch. Now I want to work on the "next" branch of developer2, getting a local branch name "developer2/junio/next".

Show 5 quoted lines
> 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.

Ah, now I understand your thinking. I admit it has a compelling elegance.

However. Would it not be confusing for newbies (and not only for them) to first reference the remote branch with "origin/next", and afterwards, you get your own development branch by using the exactly same name?

IMHO this kind of aliasing is awkward. When you want to start another topic branch on the remote branch, or want to reference the remote branch for diffs, you have to explicitly specify "remotes/origin/next", making for more typing.

Show 21 quoted lines
> 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

I didn't know about "set x" before. Thanks, you never end learning :-)

"git-checkout remotes/origin/next" does not work as expected, and if fixed, it still should guard against an existing local branch "origin/next", don't you think? (Ok, it does not work in my patch, too.)

What do you think about the setup of the default for "git-pull"?
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 14 in “Convenient support of remote branches in git-checkout”
  1. Convenient support of remote branches in git-checkoutJosef Weidendorfer, Nov 6, 2006
  2. Josef WeidendorferNov 6, 2006
  3. Junio C HamanoNov 7, 2006
  4. Josef WeidendorferNov 7, 2006
  5. Junio C HamanoNov 7, 2006
  6. Junio C HamanoNov 7, 2006
  7. Josef WeidendorferNov 7, 2006
  8. Junio C HamanoNov 7, 2006
  9. Josef WeidendorferNov 7, 2006
  10. Karl HasselströmNov 7, 2006
  11. Josef WeidendorferNov 7, 2006
  12. Karl HasselströmNov 7, 2006
  13. Josef WeidendorferNov 7, 2006
  14. Junio C HamanoNov 7, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.