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 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 option 1, because both 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.
There is no "git export" command, so instead you use the "git archive" command. By default, "git archive" produces its output in a tar format, so all you have to do is pipe that output into gzip or bzip2 or other.
svn export simply extracts all the files from a revision and does not allow revision control on it. It also does not litter each directory with . svn directories. svn checkout allows you to use version control in the directory made, e.g. your standard commands such as svn update and svn commit .
Git archive is a helpful utility for creating distributable packages of git repositories. Git archive can target specific refs of a repository and only package the contents of that ref. Git archive has several output formats that can utilize added compression.
In the Tools menu, click Import and Export. If a message appears that says Connect your GitHub account, click Connect to GitHub and then enter your GitHub credentials. Now, click Export to GitHub. In the popup, enter the GitHub repo that you want to use, and then click OK.
Probably the simplest way to achieve this is with git archive
. If you really need just the expanded tree you can do something like this.
git archive master | tar -x -C /somewhere/else
Most of the time that I need to 'export' something from git, I want a compressed archive in any case so I do something like this.
git archive master | bzip2 >source-tree.tar.bz2
ZIP archive:
git archive --format zip --output /full/path/to/zipfile.zip master
git help archive
for more details, it's quite flexible.
Be aware that even though the archive will not contain the .git directory, it will, however, contain other hidden git-specific files like .gitignore, .gitattributes, etc. If you don't want them in the archive, make sure you use the export-ignore attribute in a .gitattributes file and commit this before doing your archive. Read more...
Note: If you are interested in exporting the index, the command is
git checkout-index -a -f --prefix=/destination/path/
(See Greg's answer for more details)
I found out what option 2 means. From a repository, you can do:
git checkout-index -a -f --prefix=/destination/path/
The slash at the end of the path is important, otherwise it will result in the files being in /destination with a prefix of 'path'.
Since in a normal situation the index contains the contents of the repository, there is nothing special to do to "read the desired tree into the index". It's already there.
The -a
flag is required to check out all files in the index (I'm not sure what it means to omit this flag in this situation, since it doesn't do what I want). The -f
flag forces overwriting any existing files in the output, which this command doesn't normally do.
This appears to be the sort of "git export" I was looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With