How can I git archive an arbitrary branch?
git checkout master git archive stage | tar -czf archive.tar.gz htdocs # archives master because it's checked out.
How can I archives the stage branch, regardless of the current I’m on?
One Solution collect form web for “How can I git archive an arbitrary branch?”
git archive creates a tar archive so you don’t need to pipe its output tar, indeed it’s not doing what you expect. You are creating an tar archive of the stage branch and piping it to a normal tar command which doesn’t use its standard input but just creates its own archive of
htdocs in the working tree, independently of git.
git archive stage >stage.tar
or, for a compressed archive:
git archive stage | gzip >stage.tar.gz
To just archive the htdocs subfolder you can do:
git archive stage:htdocs | gzip >stage-htdocs.tar.gz
or, to include the folder name in the archive:
git archive --prefix=htdocs/ stage:htdocs | gzip >stage-htdocs.tar.gz
or more simply:
git archive stage htdocs | gzip >stage-htdocs.tar.gz