Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

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:

1. git clone followed by removing the .git repository directory.

2. 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.

3. git-export is a third party script that essentially does a git clone into a temporary location followed by rsync --exclude='.git' into the final destination.

None of these solutions really strike me as being satisfactory. The closest one to svn export might be an 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.

1 Answer

0 votes
by (50.2k points)

The simplest way to resolve this is through git-archive. For expanding tree you can go with

$ git archive master | tar -x -C /somewhere/else 

If you need to export from git you need an archive, for that use

$ git archive master | bzip2 >source-tree.tar.bz2

For archiving ZIP:

$ git archive --format zip --output /full/path/to/zipfile.zip master 

If you are interested in exporting index, the command is 

$ git checkout-index -a -f --prefix=/destination/path/ 

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...