Quicktip: Exporting from a bare Git repository

Published on August 06, 2009 and tagged with git  tip

Recently I had to export the latest version of a project from a bare Git repository. As it seems like there is no equivalent to svn export in Git, I had to look for an alternative. After some searching I found the following solution:

$ cd ~/example.git
$ git archive master | tar -x -C /path/to/target/folder

The first part of this statement creates a tar archive with the content of the master branch. The second part then extracts this archive to the specified folder (-x means “extract”, and -C means “change to directory”).

I hope this is useful for some of you!

3 comments baked

  • Dieter_be August 06, 2009 at 16:44

    Seems like a waste of cpu cycles to me.
    Why not just clone, and if you really don’t want the ‘.git’ directory, just remove it?
    or if you already have it checked out, cp && rm -rf .git
    keep it simple ;)

    Dieter

  • Silver Knight August 06, 2009 at 19:24

    Re: “I hope this is useful for some of you!”

    Actually, this was indeed useful for me, insofar as I had completely forgotten about the existence of the ‘git archive’ command. i agree with Dieter about just cloning and removing the .git folder to keep things simple and fast, but I gotta admit that ‘git archive’ is a useful tool and I appreciate being reminded about it. ;)

  • cakebaker August 07, 2009 at 17:16

    @Dieter, Silver Knight: Thanks for your comments!

    @Dieter: I don’t think I have to care much about cpu cycles, my repos are not that big ;-) But you are right, using ‘clone’ and then removing the ‘.git’ directory is a good alternative.

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License