user1365697
user1365697

Reputation: 5999

what is the different git :// and git+https://?

I want to add a git repository to my package.json.

{
    "dependencies": {
        "dep1": "git+https://url1",
        "dep2": "git://url1"        
}

When I run dep1 it worked for and dep2 failed. What is the diffrerent between git+https and git://? Does it is the same result ? Do I need to add something to .git?

Upvotes: 4

Views: 957

Answers (4)

rsp
rsp

Reputation: 111444

There are several protocols you can use to reference your dependencies in package.json:

git, git+ssh, git+http, git+https and git+file

As always, there are pros and cons of all of the protocols.

The difference is that with git: you're using the native git protocol and with git+https: you're accessing a git repo over HTTPS (you could also use SSH instead of HTTPS, for example, but the server needs to support it).

The git protocol is very fast but it lacks authentication or encryption.

The git+https is nice for public repos and it works well with proxies and firewalls but if you need authentication then you need to provide username and password.

The git+ssh is good for private repos because it uses your ssh public keys for authentication and no passwords need to be entered.

The git+file is for referencing repos on your own filesystem, usually local files but it can also be used with remote files with SMB or NFS.

Now, if you want to change git+http to git then it will work only if you have a git server installed and listening on the same host and serving the same repos.

It's like changing http: to ftp: in a URL - it will work only if you have an FTP server installed on the same host and serving the same files.

The bottom line is that you can use only those protocols that the server supports.

See the docs:

Upvotes: 5

user9320187
user9320187

Reputation:

your dep1 is the https protocol and the git protocol

dep1": "git+https://url1"

your dep 2 is just the git protocol

dep2": "git://url1:

The reason you were able to succesfully use dep1 and not dep2 is because you are operating with a web server that authenticates over https. You appear to not be dealing with a git server, thus dep2 is redundant and can be removed.

As to not reinvent the wheel or semi-plagiarize others. Here are some good reads for those interested.

This is a length read on git protocols if interested. https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols

This provides a good tl;dr understanding of the protocols. https://gist.github.com/grawity/4392747

Upvotes: 1

Josh Lee
Josh Lee

Reputation: 177715

It indicates to the NPM package manager that you wish to use git, with a repository URL of https://url1.

<protocol> is one of git, git+ssh, git+http, git+https, or git+file.

https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

If you were talking directly to git, you would just say git clone https://url1, but NPM can use other protocols like file:, or https: to download a tarball over plain HTTPS. Other package managers like pip support this pattern as well.

Upvotes: 1

Tyler Nichols
Tyler Nichols

Reputation: 196

Reference question https://askubuntu.com/questions/858711/what-is-the-meaning-of-githttps-github-com.

"It means the connection can use both the http and git protocols. The protocols are explained here."

Essentially you are just adding the ability for git to use HTTPS for transferring data. More detail is contained in the link.

Upvotes: 1

Related Questions