[plt-dev] Re: Git dummy needs help

From: Eli Barzilay (eli at barzilay.org)
Date: Wed May 19 05:35:50 EDT 2010

On May 19, Michael Sperber wrote:
> Eli Barzilay <eli at barzilay.org> writes:
> > It is -- it looks like you've missed `git checkout' command.  In the
> > above clone (probably in the others too, but it was too noisy to
> > follow all the details), you just need to do this:
> >
> >   git checkout release
> Doesn't work:
> ramer[5] git clone plt plt-release
> Initialized empty Git repository in /afs/informatik.uni-tuebingen.de/home/sperber/build/plt-release/.git/
> Checking out files: 100% (8688/8688), done.
> kramer[6] cd plt-release/
> kramer[7] git checkout release
> error: pathspec 'release' did not match any file(s) known to git.

You're probably cloning an existing clone ("plt") -- which doesn't
have a local `release' because you didn't do that checkout there.  If
this is correct, then you can do one of these:

  * checkout the release branch in your original repository:
      cd ~/build/plt; git checkout release

  * if you really want a new "plt-release" repository, re-clone the
    plt repository:
      cd ~/build; git checkout pltgit:plt plt-release
      cd plt-release; git checkout release

  * and if you really want a new "plt-release", and you really don't
    want to re-clone the plt repository, then just copy yours:
      cd ~/build; cp -a plt plt-release
      cd plt-release; git checkout release

My guess is that you think that `git clone' would do that last bullet,
but it isn't.  An R2 clone of an R1 repository will have remote
branches for the (local) branches in R1 -- if you later clone R3 from
R2, then R3 will have remote branches for R2's *local* ones.  Given
this you can do the following too:

  # create `release' to track the plt release in your "plt"
  cd ~/build/plt; git checkout release
  # go back to the "plt-release" clone and get the release branch
  cd ~/build; git pull

To see the connections, run `git remote -v' -- in your "plt", it will

  origin  the-url-you-got-it-from (fetch)
  origin  the-url-you-got-it-from (push)

so you can see that pull/push goes to the plt repo, whereas in
"plt-release" it will say:

  origin  .../home/sperber/build/plt/ (fetch)
  origin  .../home/sperber/build/plt/ (push)

because pushing/pulling in "plt-release" will go to *your* "plt"
clone.  Note that this is all following git's philosophy of "all
repositories are equal" -- so there is no notion of "the main
repository" that "plt-release" inherits from "plt".

Finally, if all you want is a snapshot of the `release' tree, you can
use `git archive' to get it:

  cd ~/build; mkdir plt-release; cd plt
  git archive origin/release | ( cd ../plt-release; tar x; )

or you could even tell git that your working directory is someplace

  mkdir ~/build/plt-release
  cd ~/build/plt; git --work-tree=../plt-release checkout release

but you'll need use that `--work-tree' on all git commands, or set the
$GIT_WORK_TREE environment variable.

One last note: there is also a `--mirror' flag for `git clone', but
that creates a "bare repository" -- one that has no working tree.
It's possible to use this too, but probably not a good idea if you
don't know enough how to use it.

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.