Git-style repo cloning doesn't work

Hello all!

I’ve followed the tutorial on hosting a git-style repository on ipfs, however when I try to clone the repo with the given command (git clone http://QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95.ipfs.localhost:8080/ myrepo)
it doesn’t seem to work. I get a fatal error and git says it is unable to resolve the host QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95.ipfs.localhost.
What am I doing wrong? Or is there a configuration step before I can follow this tutorial that I might’ve missed?

I set up the ipfs node with init and then ran the daemon. Everything else I did is in the Store & play videos | IPFS Docs tutorial.

Thanks for the help in advance!

1 Like

On quick glance I believe you need a base32 encoded CID to use the subdomain gateways.

Try http://bafybeieb75o7544uiy4yjl3bhyy3xlevxtwsczkwktflrgqs2n6xjjahba.ipfs.localhost:8080/myrepo

You can use ipfs cid format -b base32 -v 1 QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95 to convert your v0 CID to a v1 CID using base32.

Anatomy of a CID might be useful if you’re looking to know more about how CIDs work :slight_smile: .

Edit: That doc you linked should probably be updated for subdomain gateways.

1 Like

Thanks for the quick reply!

I tried to convert it the way you showed, but I still get the error. It can’t seem to find it, even though I can get it in my browser no problem. Anything else I could try to look into, that might help? :smiley:

I’m gonna look at https://proto.school/anatomy-of-a-cid !

1 Like

I find it strange that it’s unable to resolve localhost! Glad it’s working in the browser, but I’m not sure why your terminal doesn’t want to resolve localhost :S. Do you maybe have a git configuration that could be interfering?

For example, I can’t even get “unable to resolve host” even with git clone http://this.isnot.valid.localhost.

I’m glad the tutorial is of interest :slight_smile:, I found it helpful for learning about how CIDs are made.

1 Like

Browsers have magic to resolve these localhost-subdomains. Try http://localhost:8080/ipfs/bafybeieb75o7544uiy4yjl3bhyy3xlevxtwsczkwktflrgqs2n6xjjahba/myrepo instead.

2 Likes

I tried that as well, and this is what I get:

git clone http://localhost:8080/ipfs/$hash$ somefolder
Cloning into 'somefolder'...
fatal: unable to access 'http://localhost:8080/ipfs/$hash$/': Could not resolve host: $hash$.ipfs.localhost

I have no clue what the problem could be, I’m too new to IPFS as a whole.

Check if you have configured your IPFS gateway as a subdomain gateway (UseSubdomains: true). I don’t think it should be redirecting to the <cid>.ipfs.localhost url by default.

2 Likes

It isn’t as far as I can see:

"Gateway": {
    "APICommands": [],
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent"
      ],
      "Access-Control-Allow-Methods": [
        "GET"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ]
    },
    "NoDNSLink": false,
    "NoFetch": false,
    "PathPrefixes": [],
    "PublicGateways": null,
    "RootRedirect": "",
    "Writable": false
  }

@lidel help! Do you know why this happens?

Hi friends, this is a fun one, but there are various ways of fixing this on CLI:

  • TLDR fix: use loopback IP (127.0.0.1) instead of DNS name (localhost):

    git clone http://127.0.0.1:8080/ipfs/QmX679gmfyaRkKMvPA4WGNWXj9PtpvKWGPgtXaF18etC95/ myrepo
    

    (this way you don’t need to use subdomais on localhost)

  • alternative global fix: configure your OS (assuming Linux?) to support subdomains on localhost (eg. via nss-myhostname)

  • alternative ad-hoc fix: use go-ipfs as HTTP proxy (export HTTP_PROXY=http://127.0.0.1:8080). Caveat: it only resolves IPFS resources over HTTP (localhost gateway), you won’t be able to browse the regular web with this.

When in hurry, just do the TLDR one.

Explainer:

3 Likes

I’m on a windows machine, so I didn’t test the subdomain solution, though I might try it, if there is a way to do it on win10 as well. But the TLDR version solved it!