<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: markcummins</title>
    <description>The latest articles on DEV Community by markcummins (@markcummins).</description>
    <link>https://dev.to/markcummins</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F931412%2Ff9564331-869b-4070-9a08-6d48547a143d.png</url>
      <title>DEV Community: markcummins</title>
      <link>https://dev.to/markcummins</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/markcummins"/>
    <language>en</language>
    <item>
      <title>Make A Custom .zip of your code using Git Archive &amp; .gitattributes</title>
      <dc:creator>markcummins</dc:creator>
      <pubDate>Fri, 23 Sep 2022 20:59:19 +0000</pubDate>
      <link>https://dev.to/markcummins/make-a-custom-zip-of-your-code-using-git-archive-gitattributes-3ngn</link>
      <guid>https://dev.to/markcummins/make-a-custom-zip-of-your-code-using-git-archive-gitattributes-3ngn</guid>
      <description>&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;So I have this WordPress plugin developed, and I'm ready to submit it to for review. So I have to make a .zip file of the folder. So I right-click on the folder and click '&lt;em&gt;Compress&lt;/em&gt;' right?&lt;/p&gt;

&lt;p&gt;Well yes that works, but there's a bunch of stuff in that folder that I don't want to submit. There's a &lt;code&gt;.git&lt;/code&gt;, &lt;code&gt;.github&lt;/code&gt;, &lt;code&gt;/bin&lt;/code&gt; folder and a bunch of stuff that the plugin doesn't need. Here's how the directory looks right now:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 bash
.github
/bin
/core
/languages
/node_modules
/scripts
/tests
/vendor
.gitignore
.composer.json
plugin.php


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  Solution #1 - Git Archive
&lt;/h2&gt;

&lt;p&gt;So I turn yet again to Google, and it provides a pretty good answer. &lt;a href="https://git-scm.com/docs/git-archive" rel="noopener noreferrer"&gt;git archive&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;It takes all the files that are committed to the master branch and creates a .zip file of my plugin for me:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 bash
git archive --format zip --output \"plugin.zip\" master -0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here's how my 'plugin.zip' file looks:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 bash
.github
/bin
/core
/languages
/scripts
/tests
.composer.json
my-plugin.php


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  Solution  #1.0.1 - .gitattributes
&lt;/h2&gt;

&lt;p&gt;There's another problem, here's how my .zip file looks. It excluded everything that was in my .gitignore file from the .zip, but I really don't want to submit the &lt;code&gt;/tests&lt;/code&gt; folder or the &lt;code&gt;/bin&lt;/code&gt; folder. So back to Google I go, and the answer is to create a &lt;a href="https://www.git-scm.com/docs/gitattributes" rel="noopener noreferrer"&gt;.gitattributes&lt;/a&gt; file in the root of my directory.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 bash
.gitignore export-ignore
.gitattributes export-ignore
.github export-ignore
bin export-ignore
tests export-ignore
composer.json export-ignore
composer.lock export-ignore


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Note: Two things got me here. No. 1, you &lt;strong&gt;need to commit&lt;/strong&gt; the .gitattributes file before running the &lt;code&gt;git archive&lt;/code&gt; command, otherwise it wont work... and No .2, adding a &lt;code&gt;/&lt;/code&gt; or &lt;code&gt;./&lt;/code&gt; before a folder name wont work... (e.g. &lt;code&gt;./bin export-ignore&lt;/code&gt;)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So last time, I rerun my &lt;code&gt;git archive&lt;/code&gt; command and voila, super clean:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 bash
/core
/languages
/scripts
my-plugin.php


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  Next steps
&lt;/h2&gt;

&lt;p&gt;It would be awesome to have this work automatically when you push it to GitHub. I imagine you could set up a GitHub action that would run some tests and then create a zip file as a release.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frjfc4e4vyo6nobdsgoo8.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frjfc4e4vyo6nobdsgoo8.gif" alt="Columbo looking like the big eejit he is"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One last thing...
&lt;/h2&gt;

&lt;p&gt;Because we're lazy and we don't like remembering stuff, we can add the archive command to our .package.json. Now we just have to run &lt;code&gt;npm run archive&lt;/code&gt; and we're good to go.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "name": "...",
  "version": "...",
  "scripts": {
    "archive": "git archive --format zip --output \"mandrill-mail.zip\" master -0"
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>git</category>
      <category>productivity</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
