<?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: woss</title>
    <description>The latest articles on DEV Community by woss (@woss).</description>
    <link>https://dev.to/woss</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%2F27568%2F6d927fed-51c7-4d99-ad64-7a57c3f8adb7.png</url>
      <title>DEV Community: woss</title>
      <link>https://dev.to/woss</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/woss"/>
    <language>en</language>
    <item>
      <title>Part 1: Rehosting git repositories on IPFS</title>
      <dc:creator>woss</dc:creator>
      <pubDate>Mon, 25 Oct 2021 15:11:57 +0000</pubDate>
      <link>https://dev.to/woss/part-1-rehosting-git-repositories-on-ipfs-23bf</link>
      <guid>https://dev.to/woss/part-1-rehosting-git-repositories-on-ipfs-23bf</guid>
      <description>&lt;p&gt;Have you ever wanted to have a truly distributed way of hosting the git repository at a specific revision, tag, or branch, always available even when the remote server is down? If the answer is YES then this post is for you.&lt;/p&gt;

&lt;p&gt;In this post, you will learn how to rehost any git repository by revision, tag, or branch on IPFS.&lt;/p&gt;

&lt;p&gt;Prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the difference between a bare and normal repository. More info on &lt;a href="https://stackoverflow.com/a/42900694/2764898"&gt;StackOverflow&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;storing files on IPFS and what is the CID&lt;/li&gt;
&lt;li&gt;a running &lt;a href="https://docs.ipfs.io/how-to/command-line-quick-start/"&gt;IPFS node&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;and of course git knowledge&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let's dig in! ⚒️&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We will use a dummy repository, and its source code is located here &lt;a href="https://github.com/woss/dummy"&gt;https://github.com/woss/dummy&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic rehosting
&lt;/h2&gt;

&lt;p&gt;Clone the bare repository and enter the directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &lt;span class="nt"&gt;--bare&lt;/span&gt; https://github.com/woss/dummy dummy.git
&lt;span class="nb"&gt;cd &lt;/span&gt;dummy.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we are going to use IPFS to store the data, we need to tell git to change certain things in the bare repo to support dumb servers. IPFS is considered a dumb server because it cannot handle the updates, only reads. More info can be found here: &lt;a href="https://git-scm.com/docs/git-update-server-info"&gt;update-server-info&lt;/a&gt;, &lt;a href="https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#_dumb_http"&gt;dumb server&lt;/a&gt;, and &lt;a href="https://git-scm.com/docs/gitrepository-layout"&gt;git-repository-layout&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git update-server-info
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are ready to upload this bare repo to the IPFS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;### choose only one&lt;/span&gt;
ipfs add &lt;span class="nt"&gt;--cid-version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;             &lt;span class="c"&gt;# this pins the CID by default &lt;/span&gt;
ipfs add &lt;span class="nt"&gt;--pin&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;false&lt;/span&gt; &lt;span class="nt"&gt;--cid-version&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="nt"&gt;-r&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="c"&gt;# this will not pin the CID&lt;/span&gt;
&lt;span class="c"&gt;### choose only one&lt;/span&gt;

...
... 
... 
added bafybeihptjdt3maqy66vjwklpk6va3zavwziu6zhftqaedttux7dipzjxy &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! We have rehosted our git repository on the default branch (in our case it's &lt;code&gt;main&lt;/code&gt;) with all tag references.&lt;/p&gt;

&lt;p&gt;Now, you should be able to see your rehosted repository on your IPFS gateway or use it as a git dependency with your favorite package manager. 🎉🎉🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Advanced rehosting
&lt;/h2&gt;

&lt;p&gt;In the previous section, we did the most basic rehosting. Here you will learn how to rehost the tag, branch and a revision. We will not focus on the differences in the CID for the same revision, tag or a branch given the larger git history. We will cover that in the Part 2 of this series.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rehosting the revision
&lt;/h3&gt;

&lt;p&gt;In the normal repository to switch to a specific revision we would do this &lt;code&gt;git reset --hard 20888c33cd0f6f897703198199f33369cba8639a&lt;/code&gt;. This puts the repository into the &lt;a href="https://git-scm.com/docs/git-checkout#_detached_head"&gt;Detached HEAD state&lt;/a&gt; which is quite useful for the CI and testing the specific PR or MR. It is also very useful for rehosting since you are making sure that anybody who clones the repository will get the desired revision by default without knowing anything about the git history beforehand. This way you can be sure that the dependency behind the rehosted version will always produce the same code.&lt;/p&gt;

&lt;p&gt;That said, the tricky part is that on the bare repositories you cannot run &lt;code&gt;[git reset](https://git-scm.com/docs/git-reset)&lt;/code&gt; since the bare repo doesn't contain a working tree. Here are two different ways to accomplish &lt;code&gt;git reset&lt;/code&gt; on a bare repository:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Detaching the HEAD&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is possible to force a bare repo into the detached state by manually changing the HEAD to the revision we need. This can be done like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ git log
2021-10-19 aa97502 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, tag: v0.3.0, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Merge pull request &lt;span class="c"&gt;#1 from woss/change-1  [Daniel Maricic]&lt;/span&gt;
2021-10-19 3a227d8 &lt;span class="o"&gt;(&lt;/span&gt;origin/change-1&lt;span class="o"&gt;)&lt;/span&gt; Merge branch &lt;span class="s1"&gt;'main'&lt;/span&gt; into change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7c17223 commit to change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic] &lt;span class="c"&gt;# &amp;lt;&amp;lt;&amp;lt;&amp;lt; we need this!!!&lt;/span&gt;
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7e962ca add changefile  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

&lt;span class="c"&gt;# get the full revision, short will not work&lt;/span&gt;
❯ git rev-parse 20888c3
20888c33cd0f6f897703198199f33369cba8639a

❯ &lt;span class="nb"&gt;echo &lt;/span&gt;20888c33cd0f6f897703198199f33369cba8639a &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; HEAD

❯ &lt;span class="nb"&gt;cat &lt;/span&gt;HEAD
20888c33cd0f6f897703198199f33369cba8639a

❯ git log
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;HEAD, tag: v0.2.0, main&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! Now you can use &lt;code&gt;[shell#2]()&lt;/code&gt;and then &lt;code&gt;[shell#3]()&lt;/code&gt; to upload your repo to the IPFS.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Updating the reference to the specific revision with the default or custom branch name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are not comfortable with the &lt;strong&gt;Detached HEAD state,&lt;/strong&gt; this approach kind of cheats the refs to point the &lt;code&gt;main&lt;/code&gt; branch to a different revision you can use following. Both of the commands will create the file called &lt;code&gt;main&lt;/code&gt; ( default branch ) under &lt;code&gt;refs/head&lt;/code&gt; with the value of the revision identifier.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ git log
2021-10-19 aa97502 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, tag: v0.3.0, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Merge pull request &lt;span class="c"&gt;#1 from woss/change-1  [Daniel Maricic]&lt;/span&gt;
2021-10-19 3a227d8 &lt;span class="o"&gt;(&lt;/span&gt;origin/change-1&lt;span class="o"&gt;)&lt;/span&gt; Merge branch &lt;span class="s1"&gt;'main'&lt;/span&gt; into change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7c17223 commit to change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic] &lt;span class="c"&gt;# &amp;lt;&amp;lt;&amp;lt;&amp;lt; we need this!!!&lt;/span&gt;
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7e962ca add changefile  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

❯ git rev-parse 20888c3
20888c33cd0f6f897703198199f33369cba8639a

❯ git update-ref refs/heads/main 20888c33cd0f6f897703198199f33369cba8639a
&lt;span class="c"&gt;# or&lt;/span&gt;
❯ git update-ref HEAD 20888c33cd0f6f897703198199f33369cba8639a

❯ tree refs
refs
├── heads
│   └── main
└── tags

❯ &lt;span class="nb"&gt;cat &lt;/span&gt;refs/heads/main
20888c33cd0f6f897703198199f33369cba8639a

❯ git log
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, tag: v0.2.0, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we wanted to name the reference differently, let's say &lt;code&gt;rehosted&lt;/code&gt; instead of &lt;code&gt;main&lt;/code&gt;, to avoid confusion with the upstream &lt;code&gt;main&lt;/code&gt; branch, you can do it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ git log
2021-10-19 aa97502 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, tag: v0.3.0, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Merge pull request &lt;span class="c"&gt;#1 from woss/change-1  [Daniel Maricic]&lt;/span&gt;
2021-10-19 3a227d8 &lt;span class="o"&gt;(&lt;/span&gt;origin/change-1&lt;span class="o"&gt;)&lt;/span&gt; Merge branch &lt;span class="s1"&gt;'main'&lt;/span&gt; into change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7c17223 commit to change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic] &lt;span class="c"&gt;# &amp;lt;&amp;lt;&amp;lt;&amp;lt; we need this!!!&lt;/span&gt;
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7e962ca add changefile  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

❯ git rev-parse 20888c3
20888c33cd0f6f897703198199f33369cba8639a

❯ git update-ref refs/heads/rehosted 20888c33cd0f6f897703198199f33369cba8639a

❯ tree refs
refs
├── heads
│   └── rehosted
└── tags

❯ &lt;span class="nb"&gt;cat &lt;/span&gt;refs/heads/rehosted
20888c33cd0f6f897703198199f33369cba8639a

❯ git log
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;HEAD, tag: v0.2.0, rehosted&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rehosting the branch
&lt;/h3&gt;

&lt;p&gt;This approach is supported by the bare repo. It involves changing the refs using the &lt;code&gt;[git symbolic-ref](https://git-scm.com/docs/git-symbolic-ref)&lt;/code&gt; command. &lt;/p&gt;

&lt;p&gt;Let's say we want to point to the branch called &lt;code&gt;change-1&lt;/code&gt; we would do it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ git log
2021-10-19 aa97502 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, tag: v0.3.0, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Merge pull request &lt;span class="c"&gt;#1 from woss/change-1  [Daniel Maricic]&lt;/span&gt;
2021-10-19 3a227d8 &lt;span class="o"&gt;(&lt;/span&gt;origin/change-1&lt;span class="o"&gt;)&lt;/span&gt; Merge branch &lt;span class="s1"&gt;'main'&lt;/span&gt; into change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic] &lt;span class="c"&gt;# &amp;lt;&amp;lt;&amp;lt;&amp;lt; we need this!!!&lt;/span&gt;
2021-10-18 7c17223 commit to change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7e962ca add changefile  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

❯ git symbolic-ref HEAD refs/heads/change-1

❯ git log
2021-10-19 3a227d8 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; change-1&lt;span class="o"&gt;)&lt;/span&gt; Merge branch &lt;span class="s1"&gt;'main'&lt;/span&gt; into change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7c17223 commit to change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7e962ca add changefile  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

❯ &lt;span class="nb"&gt;cat &lt;/span&gt;HEAD
ref: refs/heads/change-1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! Now you can use &lt;code&gt;[shell#2]()&lt;/code&gt;and then &lt;code&gt;[shell#3]()&lt;/code&gt; to upload your repo to the IPFS.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rehosting the tag
&lt;/h3&gt;

&lt;p&gt;This approach is supported by the bare repo. It involves changing the refs using the &lt;code&gt;[git symbolic-ref](https://git-scm.com/docs/git-symbolic-ref)&lt;/code&gt; command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ git log
2021-10-19 aa97502 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; main, tag: v0.3.0, origin/main, origin/HEAD&lt;span class="o"&gt;)&lt;/span&gt; Merge pull request &lt;span class="c"&gt;#1 from woss/change-1  [Daniel Maricic]&lt;/span&gt;
2021-10-19 3a227d8 &lt;span class="o"&gt;(&lt;/span&gt;origin/change-1&lt;span class="o"&gt;)&lt;/span&gt; Merge branch &lt;span class="s1"&gt;'main'&lt;/span&gt; into change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7c17223 commit to change-1  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic] &lt;span class="c"&gt;# &amp;lt;&amp;lt;&amp;lt;&amp;lt; we need this!!!&lt;/span&gt;
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 7e962ca add changefile  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

❯ git tag
v0.2.0
v0.3.0

❯ git symbolic-ref HEAD refs/tags/v0.2.0

❯ git log
2021-10-18 20888c3 &lt;span class="o"&gt;(&lt;/span&gt;HEAD, tag: v0.2.0&lt;span class="o"&gt;)&lt;/span&gt; third commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 25ad655 second commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]
2021-10-18 6365c84 first commit  &lt;span class="o"&gt;[&lt;/span&gt;Daniel Maricic]

❯ &lt;span class="nb"&gt;cat &lt;/span&gt;HEAD
ref: refs/tags/v0.2.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! Now you can use &lt;code&gt;[shell#2]()&lt;/code&gt;and then &lt;code&gt;[shell#3]()&lt;/code&gt; to upload your repo to the IPFS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unpacking the git object
&lt;/h2&gt;

&lt;p&gt;It's hard to summarize what are the &lt;a href="https://git-scm.com/book/en/v2/Git-Internals-Git-Objects"&gt;git objects&lt;/a&gt; in a single sentence ( or at least it is for me ), but essentially it is the git database. All the history and file contents are there ( not the LFS ).  Since git is trying to occupy the least amount of space possible it does a lot of optimizations and one of them is packing the objects together into things called &lt;a href="https://git-scm.com/book/en/v2/Git-Internals-Packfiles"&gt;packfiles&lt;/a&gt;. The more your repository grows the more packfiles will be created and the bigger they get.  &lt;/p&gt;

&lt;p&gt;For example, at the time of writing, Linux git repo has 8358230 objects which is quite a large number and it will take some time to clone. Now, imagine unpacking these objects just so you can leverage the IPFS deduplication feature! It sounds tempting on smaller repositories, like our dummy one, which has only 19 objects, but on the big ones — definitely no!  &lt;/p&gt;

&lt;p&gt;Unpacking the packfiles and uploading them to the IPFS has these major effects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;👎🏽 significantly increases the rehosting time&lt;/li&gt;
&lt;li&gt;👎🏽 significantly increases the clone time&lt;/li&gt;
&lt;li&gt;👍🏽 IPFS deduplicates files, resulting in smaller disk usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I suggest unpacking &lt;strong&gt;AFTER&lt;/strong&gt; the &lt;code&gt;Re-hosting the *&lt;/code&gt; sections.&lt;/p&gt;

&lt;p&gt;Those who want to rehost smaller repositories and leverage the IPFS deduplication here is how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mv &lt;/span&gt;objects/pack/&lt;span class="k"&gt;*&lt;/span&gt;.pack &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;### choose only one&lt;/span&gt;
&lt;span class="c"&gt;# if using the for example nodejs exec this will break&lt;/span&gt;
git unpack-objects &amp;lt; &lt;span class="k"&gt;*&lt;/span&gt;.pack
&lt;span class="c"&gt;# but not this&lt;/span&gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.pack | git unpack-objects
&lt;span class="c"&gt;### choose only one&lt;/span&gt;

&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;.pack
&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; objects/pack/&lt;span class="k"&gt;*&lt;/span&gt;.idx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can use &lt;code&gt;[shell#2]()&lt;/code&gt;and then &lt;code&gt;[shell#3]()&lt;/code&gt; to upload your repo to the IPFS.&lt;/p&gt;

&lt;p&gt;Kudos to and inspired by: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.ipfs.io/how-to/host-git-style-repo/"&gt;https://docs.ipfs.io/how-to/host-git-style-repo/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/whyrusleeping/git-ipfs-rehost"&gt;https://github.com/whyrusleeping/git-ipfs-rehost&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.notion.so/4a3accb6fdfd77ec6ebee20bed211731"&gt;https://gist.github.com/jfmherokiller/4a3accb6fdfd77ec6ebee20bed211731&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thank you for reading. If you have found this post useful, please share and maybe subscribe.&lt;/p&gt;

</description>
      <category>git</category>
      <category>ipfs</category>
      <category>rehosting</category>
    </item>
  </channel>
</rss>
