Naftuli Kay
Naftuli Kay

Reputation: 91850

Git archive including the actual repository?

I need to create an archive of my Git project, ignoring and leaving out files specified by .gitignore, but including the actual .git repository folder. Simply running git archive master leaves out the .git folder.

Is there a way to make git archive include the .git folder but still ignore files specified by .gitignore?

Upvotes: 10

Views: 5802

Answers (3)

artless-noise-bye-due2AI
artless-noise-bye-due2AI

Reputation: 22479

git bundle is a newer command (since git 1.5, released in 2007) which allows the creation of an archive to be shared with a remote machine. The git bundle is more flexible in that it allows incremental updates and inclusion of different branches. However, you can create a bundle that use a single complete branch, such as master.

Basic usage is as follows:

$ git bundle create mybundle master

Now you can move the bundle to where you'd like to unpack it:

$ scp mybundle user@host:~/mybundle

And use git clone on that host to turn the bundle back into a repository:

$ ssh user@host
user@host $ git clone mybundle myrepo

A downside is that the remote machine also needs git. The bundle is a 'pack' file so the files would need to be 'checked out' from the bundle to create a working directory again (as opposed to tar). The set of machines with tar && git and !tar && !git is much larger than tar && !git and !tar && git. Ie, the machine likely has both or neither. Especially as you would intend to build source.

For Windows machines which likely have neither. You can use the 'zip' form.

git archive -o ../archive.zip --format=zip HEAD
zip -ur ../archive.zip .git/

.. and you have my condolences.

Upvotes: 1

Naftuli Kay
Naftuli Kay

Reputation: 91850

Looks like doing something like

# copy over all project files except for those ignored
git clone /path/to/repository /path/to/output 
# create a tar.gz archive of the project location
tar czvf projectExport.tar.gz /path/to/output
# remove the cloned directory
rm -fr /path/to/output

gets the job done. It's not the most beautiful solution in the world, but it looks like it works.

Upvotes: 3

Benjamin Bannier
Benjamin Bannier

Reputation: 58774

Since git archive just produces a tar archive you can work on that file with tar directly.

$ git archive HEAD > tar.tar
$ tar -rf tar.tar .git

tar's -r option appends the files given to the archive being worked on (specified after -f). Check tar's man page for the intimidating list of features tar has.

Upvotes: 18

Related Questions