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

Re: [RFC] git-clone: add --track <headname> support

From
Junio C Hamano <junkio@cox.net>
Date
Apr 13, 2007, 03:50 UTC
Message-ID
<7vps69gcfo.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<87slb5tbvu.wl%cworth@cworth.org>
Carl Worth <cworth@cworth.org> writes:
Show 11 quoted lines
> I'd love to get that down to:
>
> 	git clone <something with <repo> and <branch>>
> 	cd <project>
> 	git pull # as needed
>
> and then adding a subsequent branch to track would be:
>
> 	git track <something with <repo> and <branch>>
> 	git checkout <branch>
> 	git pull # as needed
I have a different suggestion.  Why not forget about 'git clone'?

After working in a clone of git.git, if you want to use the project history from another related repository, say Shawn's fastimport, what would you do?

Yes.  You add it with "git remote add".
	git remote add [options] gfi git://repo.or.cz/git/fastimport.git/

If you are _not_ working off of anybody else's work, how would you start a repository?

Yes, you just do "git init" in an empty repository.
	git init

And after that, in such a repository, certainly "git remote add" to add the FIRST remote would work, wouldn't it?

So, how about this two-command sequence instead?
 (0) Have this in $HOME/.gitconfig:
	$ cat >>$HOME/.gitconfig <<\EOF
	[branch]
        	autosetupmerge
	EOF
 (1) Prepare your working area and add the remote you want to
     track, with initial fetch:
        $ git remote add -f origin git://repo.or.cz/alt-git.git/
 (2) If you want to fork off of next, you can:
	$ git checkout -b next origin/next
The result of (2) reads like this:
	$ cat .git/config
        [remote "origin"]
                url = /opt/packrat/playpen/public/in-place/git/git.junio/
                fetch = +refs/heads/*:refs/remotes/origin/*
        [branch "next"]
                remote = origin
                merge = refs/heads/next

The [remote "origin"] section was added with (1), and [branch "next"] was done with (2). It means "When I am on 'next', if I did not give any parameter to 'git pull', I want a fetch from 'origin', and then get their 'next' branch merged.".

So after setting up your 'next' branch with a single command (2), when you are finished working in your 'next' and are ready to merge the corresponding 'next' branch of 'origin', you can just say 'git pull'. Isn't this what you want?

And I do not think trying to mix up (1) and (2) is a great idea. Whenever you are interested in yet another person's work, you do (1). And whenever you want to fork off of some remote tracking branch you have already done (1) for, you do (2). IOW, you can do more than one (2) for a single remote repository.

Previous: Junio C Hamano
Message 9 of 9 in “[RFC] git-clone: add --track <headname> support”
  1. Martin LanghoffApr 12, 2007
  2. Junio C HamanoApr 12, 2007
  3. Martin LanghoffApr 12, 2007
  4. Carl WorthApr 12, 2007
  5. Martin LanghoffApr 12, 2007
  6. Carl WorthApr 12, 2007
  7. Martin LanghoffApr 12, 2007
  8. Junio C HamanoApr 13, 2007
  9. Junio C HamanoApr 13, 2007

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.