how to git archive the project directory

my project directory structure is like this:


when I run git archive link this:

  • See Nth previous version of file
  • With Git, is it possible to re-apply an ancestor revision?
  • Add existing source code folders into Local Git Repository
  • How to have git repository in NFS partition and working-tree in local partition?
  • GIT select private key to use
  • error: RPC failed; curl 6 SSL read: error:00000000:lib(0):func(0):reason(0), err
  • git archive --format=tar.gz -o ../my_project-0.1.0.tar.gz  v0.1.0

    it archives the contents of my_project, but not the my_project directory. When I untar the archive, by default all of the directories and files are extracted in the current working directory. I want my archive to expand to a subdirectory called my_project-0.1.0. Can I do this on the git command line? Did I set up my repository wrong?

  • setting up git/github on a mac: error on reading usr/local/etc/gitconfig
  • Using GitBash packaged with Atlassian, SourceTree “Vagrant Up” doesn't work
  • Delete branch with jgit not working as expected
  • Using git with a PHPFog Wordpress app
  • Can I edit two files then make one commit using GitHub Web-based editor?
  • Gitweb - name of last person to commit
  • 2 Solutions collect form web for “how to git archive the project directory”

    Use --prefix. From the docs:

    Prepend <prefix>/ to each filename in the archive.

    Thus you can do:

    git archive --format=tar.gz --prefix=my_project/ -o ../my_project-0.1.0.tar.gz v0.1.0

    The trailing / is important.

    I’ll answer my own question.

    Do the git archive like this:

    git archive --format=tar.gz --prefix=my_project-0.1.0/ -o ../my_project-0.1.0.tar.gz  v0.1.0

    Note the trailing / after the prefix.

    Git Baby is a git and github fan, let's start git clone.