Ignoring .gitignore when running git archive

You can exclude files and/or directories from git archive by using the .gitattributes file.

  1. Create a file named .gitattributes in your project root (if it doesn't exist).
  2. Edit the file: Each exclusion should have a file pattern followed by "export-ignore":

    .gitattributes export-ignore
    .gitignore export-ignore
    /mytemp export-ignore
    
  3. Make sure to ignore the .gitattributes file itself!

  4. Make sure to commit the .gitattributes file, or git archive won't pick up the settings.

Then feel free to use your git archive -o archive.zip command, or variant.

Source here


I don't think you are going to be able to use 'git archive' for what you hope to achieve. 'git archive' works on commits and your binary files simply won't be visible. Note 'git archive' is so commit centric that you can use git archive directly in a bare repository where no source controlled files exist explicitly.


It is not possible to include files in a git-archive if they are ignored (via .gitignore) from version control.

In my workaround, I append the files I need afterwards.

git archive --format=tar -o repo.tar HEAD
tar --append --file=repo.tar thirdparty/binary
gzip repo.tar

Note that appending to a tar.gz isn't easy, so I first create an uncompressed archive first, then add the binaries, then compress.

Tags:

Git