I've been wondering whether there is a good "git export" solution that creates a copy of a tree without the .git
repository directory. There are at least three methods I know of:
git clone
followed by removing the.git
repository directory.git checkout-index
alludes to this functionality but starts with "Just read the desired tree into the index..." which I'm not entirely sure how to do.git-export
is a third party script that essentially does agit clone
into a temporary location followed byrsync --exclude='.git'
into the final destination.
None of these solutions really strike me as being satisfactory. The closest one to svn export
might be option 1, because both those require the target directory to be empty first. But option 2 seems even better, assuming I can figure out what it means to read a tree into the index.
I needed this for a deploy script and I couldn't use any of the above mentioned approaches. Instead I figured out a different solution:
If you want something that works with submodules this might be worth a go.
Note:
Assumptions:
This will copy all contents, minus the .dot files. I use this to export git cloned projects into my web app's git repo without the .git stuff.
Plain old bash works just great :)
I just want to point out that in the case that you are
Then you can just use
cp foo [destination]
instead of the mentionedgit-archive master foo | -x -C [destination]
.I have another solution that works fine if you have a local copy of the repository on the machine where you would like to create the export. In this case move to this repository directory, and enter this command:
GIT_WORK_TREE=outputdirectory git checkout -f
This is particularly useful if you manage a website with a git repository and would like to checkout a clean version in
/var/www/
. In this case, add thiscommand in a.git/hooks/post-receive
script (hooks/post-receive
on a bare repository, which is more suitable in this situation)You can archive a remote repo at any commit as zip file.